So I have the following code:
<h3 th:if="#{${'footer.message.' + receiptProperties.url}? : '(NOTHING)'}" th:utext="#{${'footer.message.' + receiptProperties.url}}"></h3>
receiptProperties.url = a name given to a tenant, such as ABC, DEF etc. So the key in the messages.properties file would be something like footer.message.ABC=Hello ABC!
The dynamically created message key displays correctly, however, if the key such as footer.message.GHI does not exist in the properties file, then instead of not displaying anything at all, the following is shown on the page: ??footer.message.GHI_en??
Is there any way in Thymeleaf to accurately check if the dynamically created key exists in the properties file?
The messages utility object has methods that can be used for this. You could use an expression like:
${#messages.msgOrNull('footer.message.' + receiptProperties.url) == null ? 'Invalid key' : 'Valid key'}
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