Map with custom formatter in thymeleaf view
I got third way working for me. I created a LongCurrencyService which calls the parse and print methods of my Formatter-class.
@Named
@Singleton
public class LongCurrencyService {
public static String LongToStringCurrency(Long value) {
LongCurrencyFormatter longCurrencyFormatter = new LongCurrencyFormatter();
return longCurrencyFormatter.print(value, Locale.GERMAN);
}
public static Long StringToLongCurrency(String value) throws ParseException {
LongCurrencyFormatter longCurrencyFormatter = new LongCurrencyFormatter();
return longCurrencyFormatter.parse(value, Locale.GERMAN);
}
}
In my Thymeleaf I use that EL:
<h1 th:text="${@longCurrencyService.LongToStringCurrency(test)}"></h1>
which prints 33,33 as wanted.
My way is working for me, but I don't if I should accept my own answer. It is not the answer to my question, how to annotate a map with a formatter.