Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access from Thymeleaf to class field

Tags:

java

thymeleaf

How to access from Thymeleaf to some simple POJO static property ? For example:

public final static int PROJECT_NAME_MAX_LENGTH = 255;

how to type:

<input type="text" th:maxlength="??" />
like image 209
Cichy Avatar asked Aug 04 '14 14:08

Cichy


People also ask

How do you pass parameters in Thymeleaf?

Request parameters can be easily accessed in Thymeleaf views. Request parameters are passed from the client to server like: https://example.com/query?q=Thymeleaf+Is+Great! In the above example if parameter q is not present, empty string will be displayed in the above paragraph otherwise the value of q will be shown.

How do I get a request attribute in Thymeleaf?

Another way of accessing request parameters in thymeleaf is by using #httpServletRequest utility object which gives direct access to javax. servlet. http. HttpServletRequest object.

How do I print data from Thymeleaf?

You can use the "th:text=#{variable}" to print a variable in the Thymeleaf.


1 Answers

Since you are using Spring, thymeleaf has access to the EL provided by Spring. You should therefore be able to use

<input type="text" th:maxlength="${T(com.example.MyType).PROJECT_NAME_MAX_LENGTH}" /> 
like image 91
Sotirios Delimanolis Avatar answered Sep 17 '22 13:09

Sotirios Delimanolis