Thymeleaf utility methods for Booleans

January 04, 2020 No comments Thymeleaf Utility Booleans

1. Introduction

Thymeleaf is an HTML template engine specially designed for Java-based applications. The engine comes with utility classes available on the front-end level, that can be useful in processing variables before presenting them on the website. In this article, we will present utility methods for Boolean objects. The implementation of Boolean utility methods can be found in the official Thymeleaf GitHub Repository.

2. Available utility methods for Boolean objects

Thymeleaf provides several methods to manipulate Boolean object directly on the template.

Method Purpose Description
${#bools.isTrue(obj)}
${#bools.arrayIsTrue(objArray)}
${#bools.listIsTrue(objList)}
${#bools.setIsTrue(objSet)}

Evaluate a condition in the same way that it would be evaluated in a th:if tag Also works with arrays, lists or sets
${#bools.isFalse(cond)}
${#bools.arrayIsFalse(condArray)}
${#bools.listIsFalse(condList)}
${#bools.setIsFalse(condSet)}

Evaluate with negation Also works with arrays, lists or sets
${#bools.arrayAnd(condArray)}
${#bools.listAnd(condList)}
${#bools.setAnd(condSet)}

Evaluate and apply AND operator
${#bools.arrayOr(condArray)}
${#bools.listOr(condList)}
${#bools.setOr(condSet)}

Evaluate and apply OR operator

3. Conclusion

In this article, we presented Thymeleaf utility methods for Boolean objects. The utility can be useful for retrieving and comparing Boolean variables on the website.

{{ message }}

{{ 'Comments are closed.' | trans }}