Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf: Use #dates.format() function for format date with internatinalization.

I am using Thymeleaf #dates.format() function for format date in view layer. I create one internatinalization properties file for pic the date format. i am using #dates.format(date, (#{app.dateformat})) function like this. but Thymeleaf throw an parse exception. Because thymeleaf now resolve the app.dateformat. How i use date format internationalization way in thymeleaf. Following is an exception:

org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'
like image 534
Harmeet Singh Taara Avatar asked Mar 02 '15 11:03

Harmeet Singh Taara


People also ask

What is the advantage of Thymeleaf?

Thymeleaf provides useful formatting utilities such as ${#calendars. format(...)} , ${#strings. capitalize(...)} which are well integrated with Spring e.g. you can pass model beans propagated by Spring MVC into these functions. The build/deploy/test feedback loop is shortened by Thymeleaf.

Is Thymeleaf necessary?

No they aren't necessary, in fact most new projects that require web-pages are using single page applications now like Angular, React, Vue, ... over thymeleaf or jsp.

Is Thymeleaf backend or frontend?

Thymeleaf is used to render the frontend, e-mail templates and also Handlebars fragments for the dynamic part of our EnSupply frontend. Even though Thymeleaf has a huge number of features, its learning curve is relatively flat. Due to its good integration into the Spring ecosystem can be productive from day one on.

What is Thymeleaf in HTML?

What is Thymeleaf? The Thymeleaf is an open-source Java library that is licensed under the Apache License 2.0. It is a HTML5/XHTML/XML template engine. It is a server-side Java template engine for both web (servlet-based) and non-web (offline) environments. It is perfect for modern-day HTML5 JVM web development.


1 Answers

You should use this syntax instead :

${#dates.format(date, #messages.msg('app.dateformat'))}

#messages : utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.

Source

like image 80
lgd Avatar answered Oct 13 '22 04:10

lgd