What is Thymeleaf?
Thymeleaf is Java library and template engine that supports XML/XHTML/HTML5 template engines. It is very well suited for processing the XHTML and HTML5 documents in the web applications. Also it can process the XML documents while work as offline applications. This is a new template engine and adopted by many of the projects which are looking for the alternative to JSP. It has separate module for Spring MVC integration. This helps the spring developers to use thymeleaf out of the box from their spring applications.
The latest version of this template engine is 2.1. As rightly said, this template engine is evolving and we could see lot of optional modules for integrating to the other frameworks. This post publishes the collection of tutorials on thymeleaf in JavaBeat.
- Thymeleaf Hello World Example : This tutorial is Hello World example for the template engine framework Thymeleaf. This framework is released few years back and many projects adopted this template engine framework. In simple terms, Thymeleaf is a Java library which can be easily integrated to any Java applications or frameworks like Spring to use as the view templates. Thymeleaf uses XML/XHTML/HTML5 for the transformations.
- WebContext in Thymeleaf : If you look at the example, it uses some kind of context to transfer the variables across its application. The same way how ServletContext or SpringApplicationContext works, Thymeleaf has its own context framework to maintain its context across the applications and retain the values throughout the application scope. This tutorial explains the various types of context available and default values stored with the thymeleafís context environment.
- Expression Language in Thymeleaf : When we work with web frameworks, one of the important feature is the simplification of using the expression languages. This tutorial explains the various syntax used by the Thymeleaf framework for accessing the values using its expression syntax. Look at the below list of various types of expression syntax supported by this framework.
- Context Objects in Thymeleaf : Thymeleaf have number of default objects in the context which are more than just the basics objects like session, request, etc., there are many other utility objects can be accessed in the context. This tutorial explains the default context objects used in the Thymeleaf framework.
- org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating OGNL expression : When you work with Thymeleaf application, you would have encountered the TemplateProcessingException exceptions. The problem is the use of default context variables.
- How To Set Attributes in Thymeleaf Template using th:attr? : This tutorial explains how to set the attribute to the template at the time of processing. This feature is very useful for creating the templates. Thymeleaf provides very easy syntax for just adding the attributes dynamically from the properties files or context variables.
- How To Use th:each For Iteration In Thymeleaf Template? : This tutorial explains how to iterate the list of values from an object. For Iteration In Thymeleaf Template, it provides th:each attribue for using inside a table element to iterate over the list of objects and display the list. This feature also provides iterationStatus context to retrieve the extra details about size of the list, row count, whether that is the first or last element, etc. This feature is very useful for creating the table list with the dynamic values.
- How To Use Switch Statement (th:switch) In Thymeleaf Template? : This tutorial explains how to use the switch statements inside Thymeleaf template. Thymeleaf provides th:switch attribute for using switch functionality. This feature is extension of my previous example on iteration in thymeleaf template.