Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Qute guide, first Type-safe template example does not compile #18550

Closed
marc-bouvier opened this issue Jul 8, 2021 · 1 comment · Fixed by #18611
Closed

In Qute guide, first Type-safe template example does not compile #18550

marc-bouvier opened this issue Jul 8, 2021 · 1 comment · Fixed by #18611
Assignees
Labels
Milestone

Comments

@marc-bouvier
Copy link

Describe the bug

The first example about Type-safe template does not compile.
It throws a io.quarkus.qute.TemplateException that points the need for checked parameter.

Which pages

Stack Trace

Caused by: io.quarkus.qute.TemplateException: Found template problems (1):
[1] Incorrect expression found: {name}
        - Only type-safe expressions are allowed in the checked template defined via: org.acme.quarkus.sample.HelloResource $Templates.hello(); an expression must be based on a checked template parameter [], o
r bound via a param declaration, or the requirement must be relaxed via @CheckedTemplate(requireTypeSafeExpressions = false)
        - at HelloResource /hello.txt:1

A working example might be

Either

    @CheckedTemplate(requireTypeSafeExpressions = false)
    public static class Templates {
        public static native TemplateInstance hello(); 
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public TemplateInstance get(@QueryParam("name") String name) {
        return Templates.hello().data("name", name);  
    }

Or :

    @CheckedTemplate
    public static class Templates {
        public static native TemplateInstance hello(String name); 
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public TemplateInstance get(@QueryParam("name") String name) {
        return Templates.hello(name);  
    }

Here is what comes to my mind about this.

  • Making the sample compile by adding early noise with optional parameter (requireTypeSafeExpressions = false)
    • Maybe along with a note that explains briefly why there is (requireTypeSafeExpressions = false) and tells that it will be explained a few paragraphs later

or

@marc-bouvier marc-bouvier changed the title In Qute guide In Qute guide, first Type-safe example does not compile Jul 8, 2021
@marc-bouvier marc-bouvier changed the title In Qute guide, first Type-safe example does not compile In Qute guide, first Type-safe template example does not compile Jul 8, 2021
@gsmet
Copy link
Member

gsmet commented Jul 8, 2021

@mkouba could you have a look at this one?

@mkouba
Copy link
Contributor

mkouba commented Jul 9, 2021

Yes, it should be the variant with public static native TemplateInstance hello(String name). The ref guide should be correct: https://quarkus.io/guides/qute-reference#typesafe_templates

@mkouba mkouba self-assigned this Jul 9, 2021
@quarkus-bot quarkus-bot bot added the area/qute The template engine label Jul 9, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 9, 2021

/cc @mkouba

@mkouba mkouba transferred this issue from quarkusio/quarkusio.github.io Jul 9, 2021
mkouba added a commit to mkouba/quarkus that referenced this issue Jul 12, 2021
- to reflect the defaults:
CheckedTemplate#requireTypeSafeExpressions=true
- resolves quarkusio#18550
@mkouba mkouba added this to the 2.1 - main milestone Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants