What's new in Thymeleaf 1.1
A new expression system: the Standard Expressions
The old value expression system had a series of limitations, especially regarding to operators to be applied between expressions. In Thymeleaf 1.1 this system is substituted in both the Standard and SpringStandard dialects by a new Standard Expression system, which builds on the previous one and keeps all of its syntax — so that all your templates still work alright — and adds the following new features:
- Numeric literals: 1, 32, 42.3, 11.34, etc.
- Unary operators: ! (boolean negation), - (numeric minus sign)
- String operators: + (String concatenation)
- Numeric binary operators and comparators: +, -, *, /, %, >, <, >=,<=
- Boolean binary operators: and, or
- Equality checks: ==, !=
For example, now you can concatenate Strings easily in your expressions, like:
No more Value Processors
Thymeleaf 1.0 defined three types of processors: attribute processors, tag processors and value processors. The latter type, value processors, were defined as utility objects that executed common logic needed to process expressions, usually called from attribute or tag processors.
This resulted in code similar to this in order to execute an expression from an attribute value:
Thymeleaf 1.1 completely removes the concept of value processor from its API, so that it allows each dialect to implement expression resolution in the way preferred by its developers.
For example, the Standard and SpringStandard dialects now implement the resolution of Standard Expressions using the StandardExpressionProcessor class, so that all the code above can now be written in a much more concise way:
New th:substituteby attribute in the standard dialects
Thymeleaf 1.1 adds a new attribute to both the Standard and SpringStandard dialects called th:substituteby, which works very similarly to the already existing th:include for including a fragment from an external template, but actually substitutes the host tag by the fragment's, instead of only substituting its contents — which is what th:include does.
In order to see the differences between these tags, the following fragment:
Referenced in your template with both a th:include and a th:substituteby:
The results will be slightly different, because th:include will only copy the fragment's contents whereas th:substituteby will actually replace the host tag by the whole fragment:
New XHTML DTDs for the standard dialects
The new th:substituteby attribute requires a change in the existing Thymeleaf DTDs (those specified with a DOCTYPE SYSTEM clause), in order to include this new attribute and allow its validation.
New versions of the DTDs for the Standard and SpringStandard dialects have been created, so that the old DOCTYPE declarations:
Can now be substituted by new versions containing the new attribute:
New date utility functions
Thymeleaf 1.1 adds new functions to the #dates and #calendars utility function objects, which can be used in variable expressions as usual:
Since 1.1.2, also:
Changes in condition evaluation
Condition evaluation —used in th:if or th:unless attributes, for example— changes a bit in Thymeleaf 1.1 so that the Strings "false", "no" and "off" now evaluate as false, instead of true as they did before (Thymeleaf 1.0 evaluated as true any non-null String).
When a template is stored into the cache, Thymeleaf 1.1 now scans its whole DOM tree in order to determine which nodes —and also entire trees— are not executable (because no attribute or tag processor can be applied to them), and marks those DOM nodes so that they are skipped when actually processing the template.
This improves performance by allowing the engine to focus only on those nodes that trigger real execution logic once it retrieves a template from the cache.
Fixed HTML entity processing
Thymeleaf 1.1 fixes a behaviour in version 1.0 regarding HTML entities ( , £, á, etc.) that made the engine raise an exception like this:
...in the following cases:
- When th:utext was used for writing a String containing one of such entities.
- In HTML5 templates, every time an HTML entity was used.
Thymeleaf 1.1 fixes this so that not only the presence of these entities does not cause an error, but also they are preserved as they are (this is, in escaped form) in output.
Modified LEGACYHTML5 mode (since 1.1.2)
For performance and reliability reasons, the LEGACYHTML5 mode now uses nekoHTML 1.9.15 or newer as an auxiliary library instead of htmlcleaner, which was used in previous versions.
Dart inlining mode (since 1.1.2)
Minor modifications and bug fixing
Of course, many minor modifications and bug fixes have been applied too. In order to know more, have a look at the changelogs.