JSTL fmt: message and resource bundle

I want to set the "dir" property of my table from a locale-based resource set.

Here is a snippet:

<fmt:setBundle basename="class.path.to.resource.bundle"/> <table align=center class="" dir=<fmt:message key="registration.direction"/>> 

When the page is displayed, I get the following:

  <table align=center dir=???registration.direction???> 

I have two resource packs for English and Arabic.

registration.direction = ltr → English

registration.direction = rtl → Arabic

Tell me what am I doing wrong? Depending on the locale, the directory should have "ltr" or "rtl".

thanks

BR SC

+6
java jstl struts2
source share
1 answer

two things

1) I would add a variable to save the result of the message in

 <fmt:message key="registration.direction" var="direction" /> 

then

2) I would do the following with your code

  <fmt:setBundle basename="class.path.to.resource.bundle"/> <fmt:message key="registration.direction" var="direction" /> <table align=center class="" dir="${direction}"> 

Now, as far as your resource packs are usually, you should have the following structure for your resource packs

 /foo/bar/MyResourceBundle.properties /foo/bar/MyResourceBundle_en.properties /foo/bar/MyResourceBundle_en_US.properties /foo/bar/MyResourceBundle_<lang>[_COUNTRY[_VAR]].properties 

If your package is not structured this way, this may be your problem.

Ensure that all keys that should be available are defined in MyResourceBundle with reasonable defaults.

I am correcting this answer as I am not sure that my comment was lost in a hidden function.

With the fact that you are using Struts 2, I get the impression that you are using the i18n interceptor. The interceptor will save the current language in the sesion variable with the name WW_TRANS_I18N_LOCALE. Thus, you should be able to get to it and set the locale for the JSTL tags using the following:

 <fmt:setLocale scope="session" value="${sessionScope.WW_TRANS_I18N_LOCALE}" /> 

Hope this works for you.

+6
source share

All Articles