Skip to content

Conversation

@ddovnar
Copy link

@ddovnar ddovnar commented Apr 18, 2024

New extension module for working with Thymeleaf mvc templates.

How to use

1. Add class and properties into ResourceConfig:

...
config.property(ThymeleafMvcFeature.TEMPLATE_BASE_PATH, "WEB-INF/templates/");
config.register(ThymeleafMvcFeature.class);
...

2. Create template files and localized messages files

Templates files should be placed in the resources folder in the project. For example:

jersey-thymeleaf-resources

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p th:text="${firstName}">DEFAULT</p>
<p th:text="${lastName}">DEFAULT</p>

<p th:text="#{label.title}">List</p>
</body>
</html>

Messages properties files for localization:
index.properties

label.title = List of Products

index_de.properties

label.title = Produktliste

3. Example how to use in the controller class

@Path("/demo1")
    @GET
    public Viewable mvc() {
        return new Viewable("/index.html", "Fruit Index Page");
    }

    @GET
    @Template(name = "/index.html")
    @Path("/demo2")
    @Produces(MediaType.TEXT_HTML)
    public Map<String, Object> mvc1(@QueryParam("lang") String lang) {
        Map<String, Object> model = new HashMap<>();
        model.put("firstName", "Demo");
        model.put("lastName", "User");
        model.put("lang", lang);
        return model;
    }

@jansupol
Copy link
Contributor

Please see our wiki. Also, each file must have a copyright header with the copyright year (2024 this year) and the license, just like the other files in the repository.

@jansupol
Copy link
Contributor

jansupol commented Apr 25, 2024

@ddovnar Thank you for adding the copyright header, but the copyright year needs to be 2024. We also have the issue with ECA, as the check says your email dmitriy.dovnar@ar*on... cannot be found in Eclipse.

@senivam senivam merged commit 115da13 into eclipse-ee4j:3.0 Apr 30, 2024
@senivam senivam added this to the 3.0.14 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants