I end up with a lot of code like:
<section layout:fragment="content" th:remove="tag">
<p>content section</p>
</section>
and
<section th:switch="${session['SOME_KEY'" th:remove="tag">
<section th:case="${'BadCredentialsException'}" th:remove="tag">
Invalid username/password
</section>
<section th:case="${'UsernameNotFoundException'}" th:remove="tag">
Invalid username/password
</section>
<section th:case="${'DisabledException'}" th:remove="tag">
Account is blocked, contact your admin
</section>
<section th:case="*" th:remove="tag">
Something went wrong
</section>
</section>
Note the th:remove="tag" to not display the in this case section tags as I don't neem them.
Is this the proper way to do this?
Since Thymeleaf 2.1 there's a sythetic th:block
tag available. It's container attribute that is removed after execution (see documentation).
So you end up with code like this :
<th:block layout:fragment="content">
<p>content section</p>
</th:block>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With