In a form I have radio buttons that correspond to an enum:
public enum EleType {
INTEGER,
CHARACTER
}
The html of the form is:
<div class="form-check" th:each="elementType : ${T(org.example.sorting.EleType).values()}">
<input type="radio" class="form-check-input" name="elemType" th:id="${{elementType}}" th:field="*{elementType}" th:value="${{elementType}}" />
<label th:for="${{elementType}}" th:text="${{elementType}}">Elem Types</label>
</div>
This gives me radio buttons with labels "INTEGER", "CHARACTER".
I would like to translate these strings using the messages.properties file. So with label.pages.sorting.INTEGER=Integer
and label.pages.sorting.CHARACTER=Character
in the messages.properties file I tried:
<label th:for="${{elementType}}" th:text="#{label.pages.sorting.${{elementType}}}">Elem Types</label>
which does not work since the ${{elementType}}
is not evaluated inside the #{...}
.
How can I make this work? Or is there another/better way to introduce localization of enum?
I figured it out myself. The following works:
<label th:for="${{elementType}}" th:text="#{'label.pages.sorting.'+${{elementType}}}">Elem Types</label>
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