Hi folks,
I noticed a pretty weird behavior of the Qute template engine when used with Quarkus JAX-RS. It's a bit longish to explain, but I have a reproducer in github as well (
https://github.com/ivannov/qute-include).
So, this is a very simple project with a couple of templates, an endpoint and one POJO that is not a CDI bean. To start with, here's the POJO:
public class TemplateContext {
public String printData(String data) {
return data;
}
}The endpoint creates an instance of this POJO and passes it as a parameter to the template instance that is returned:
@Path("/")
public class QuteResource {
@CheckedTemplate
public static class Templates {
public static native TemplateInstance test(TemplateContext context);
}
@GET
@Produces(MediaType.TEXT_HTML)
public TemplateInstance get() {
return Templates.test(new TemplateContext());
}
}
If the template itself uses directly the POJO, it works fine:
<body>
Hello from test template
<p>
Context data: {context.printData("Hello")}
</body>
This will yield as expected:
Hello from test templateContext data: Hello
But, if I extract the Context data: .... line in a template and include that new temple in the above one:
include.html:
Context data: {context.printData("Hello")}
test.html:
<body>
Hello from test template
<p>
{#include include /}
</body>
This would yield:
Hello from test templateContext data: NOT_FOUND
So, when I moved calling the POJO method into an included template, the method is not resolved anymore.
Why I think it's weird is that if the method doesn't take parameters, it works fine even when the template is included.
Moreover, if I call the method both in the base and in the included templates, it works fine too:
<body>
Hello from test template
<p>
Context data: {context.printData("Hello from base")}
<p>
{#include include /}
</body>
Yields:
Hello from test templateContext data: Hello from base
Context data: Hello
So, am I doing something wrong? Maybe there are better ways to pass such POJOs with helpful utility functions between templates? But still, this behavior is quite strange: when the base template calls the method it can be resolved in the included one, otherwise - not.
Thanks,
Ivan