I am trying to localize the currency in my JSP web application, the problem is when I request the locale, I get only the language code ("en") instead of the full language and country code ("en_US"). The problem with this is that formatNumber does not work when the setLocale value does not contain the language and country code.
I can solve this by checking the language of the language at the top of the jsp page and setting the default country code for several languages and then setting the value to setLocale, but this method looks pretty ugly for me. Is there a better way to do this?
Here's how I do it now:
<c:choose>
<c:when test="${pageContext.response.locale == 'cs'}">
<f:setLocale value="cs_CZ" />
</c:when>
<c:otherwise>
<f:setLocale value="en_US" />
</c:otherwise>
</c:choose>
<f:formatNumber type="currency" value="${product.price}" currencyCode="CZK"/>
source
share