Thymeleaf, fragments and default parameters

Thymeleaf allows a signature of a fragment without explicit parameters like this: <div th:fragment=”my_fragment”> <p th:text=”${content}”></p> <p th:text=”${defaultParameter}”></p> </div> To call this fragment and pass content and defaultParameter you may call the fragment as follows: <!– both parameters not specified –> <div th:replace=”fragments :: my_fragment”></div> <!– only content parameter specified –> <div th:replace=”fragments :: my_fragment(content=”a”)”></div> … Read more

How to add source code comments in Thymeleaf templates that don’t get included in generated HTML?

Version 2.1 is released so now you can upgrade your libraries and use comments in your code. With this version developers are able to use parser-level comment blocks: <!–/* This code will be removed at thymeleaf parsing time! */–> and prototype-only comment blocks: <span>hello!</span> <!–/*/ <div th:text=”${…}”> </div> /*/–> <span>goodbye!</span> Detailed explanation can be found … Read more

Spring MVC 3.2 Thymeleaf Ajax Fragments

Here is an approach I came across in a blog post: I didn’t want to use those frameworks so in this section I’m using jQuery to send an AJAX request to the server, wait for the response and partially update the view (fragment rendering). The Form <form> <span class=”subtitle”>Guest list form</span> <div class=”listBlock”> <div class=”search-block”> … Read more

setting up a value for a variable name in thymeleaf

You can use local variables. Declare an HTML element with a th:with attribute. For example <div th:with=”someVariable=${someValue}”> The documentation states When th:with is processed, that [someVariable] variable is created as a local variable and added to the variables map coming from the context, so that it is as available for evaluation as any other variables … Read more

How to bind an object list with thymeleaf?

You need a wrapper object to hold the submited data, like this one: public class ClientForm { private ArrayList<String> clientList; public ArrayList<String> getClientList() { return clientList; } public void setClientList(ArrayList<String> clientList) { this.clientList = clientList; } } and use it as the @ModelAttribute in your processQuery method: @RequestMapping(value=”/submitQuery”, method = RequestMethod.POST) public String processQuery(@ModelAttribute ClientForm … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)