How to make fmt: setLocale work in fmt: formatNumber with only language code in JSP?

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"/>
+3
source share
2

, . . - Filter , JSP.

. , HttpServletResponse#getLocale(), - . HttpServletRequest#getLocale(), , :

${pageContext.request.locale}

, . , . A Filter - .

+4

Stripes!! , ActionBeanContext:

<c:set var='curLocale' value='${actionBean.context.locale}'/>

! ! Stripes - !

, <fmt:setLocale>, Stripes Stripes. , - !! - Stripes:

http://www.stripesframework.org/display/stripes/Localization

+4

Source: https://habr.com/ru/post/1732675/


All Articles