You cannot invoke a JavaScript function within an expression. Your container will generate content using expressions before the client begins processing the JavaScript on the page, so there is no way for the container to resolve the expression to invoke the function as is.
You have two choices:
- Refactor that logic to your backend
For example, if you are using servlets, this method would need to be accessible:
private String getNumberFormatPattern(int nbDecimal) {
String numberFormatPattern1 = "##,";
String numberFormatPattern2 = "0.";
for (int i = 0; i < nbDecimal; i++) {
numberFormatPattern1 += "#";
numberFormatPattern2 += "0";
}
return numberFormatPattern1 + numberFormatPattern2;
}
You could then make this value available for an expression by associating it with the request:
request.setAttribute("numberFormatPattern", getNumberFormatPattern(4));
And reference it like so in an expression:
<fmt:formatNumber type="number" pattern="${ numberFormatPattern }" value="${ toto.montant }" />
- Refactor that logic into a custom function
Here is a straight-forward guide on the registration and usage of a custom function. You'd just need to replace the charAt function with your getNumberFormatPattern()
function.