, By changing to jdk " /> , By changing to jdk " /> , By changing to jdk "/>

Struts 2 and JDK 17 numbers in locale

201 views Asked by At

With struts 6.3.0.1 and jdk 8 the below generates 1, 2, 3,

     <s:iterator begin="1" end="3">
                <s:property value="top"/>,
     </s:iterator>

By changing to jdk 17 It generates ۱, ۲, ۳, ( these are Persian numbers for 1, 2, 3,)

I set the struts.locale to fa_IR

<constant name="struts.locale" value="fa_IR" />

The site is Multilanguage and the i18n interceptor is used.

It may be a good feature but the site is built in the way that it works with English numbers. Anyway, is it any way that I can have numbers in English regardless of locale

I tried to fix it by session.setAttribute(Config.FMT_LOCALE, new Locale("en", "US")); but no luck

1

There are 1 answers

0
Roman C On BEST ANSWER

To print English numbers you should change a Locale. But you only print em in the <s:iterator> tag. You should know how to get a current Locale from the ActionContext in JSP.

Then you save a current locale to the variable before you change it

<s:set var = "old_locale" value = "%{#context.locale}" />

<!-- then change a current locale -->

<s:set var = "%{#context.locale}" value = "%{new java.util.Locale("en", "US")" />

<!-- print numbers with a new locale -->

<s:iterator begin="1" end="3">
    <s:property value="top"/>,
</s:iterator>

<!-- then return a current locale back -->

<s:set var = "%{#context.locale}" value = "%{#old_locale}" />