Skip to content

How to refer to a static method in Thymeleaf html in java?

I need to use the getMoneyIntoWords() method in the invoice html. But I am getting errors. Refer the code and errors below

// Added below method in

 public String getMoneyIntoWords(String input) {

        MoneyConverters converter = MoneyConverters.ENGLISH_BANKING_MONEY_VALUE;

        String str = converter.asWords(new BigDecimal(input));

        return StringUtils.capitalize(str.split("£")[0]);


<td rowspan="2" colspan="2">
         <span th:text="${MoneyUtil.getMoneyIntoWords(invoice.totalAmountAfterTax)} +'only'" />


Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method moneyIntoWords(java.lang.Integer) on null context object



You need special syntax to call a static method in Thymeleaf:

<span th:text="${T(} +'only'" />

You will need to use the full qualified name of the MoneyUtil class.

User contributions licensed under: CC BY-SA
7 People found this is helpful