开发者

JSTL fmt:message and resource bundle

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

Here is snippet:

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

When the page renders I get this:

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

I have two resource bundles for english and arabic.

registration.direction = ltr -> English

registration.d开发者_如何转开发irection = rtl -> Arabic

Please tell what I am doing wrong? The dir should have "ltr" or "rtl" depending on the locale.

Thanks

BR SC


two things

1) I would add a variable to store the message result 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 bundles, typically You should have the following structure for your resource bundles

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

If your bundle is not structured in this fashion that might be some of your problem.

Make sure that all keys that are expected to be available are defined in MyResourceBundle with reasonable defaults.

I'm amending this answer as I'm not sure if my comment got lost in a hide function.

With the fact that you are using Struts 2, I'm under the impression that you're using the i18n interceptor. The interceptor will store the current locale in the sesion variable named WW_TRANS_I18N_LOCALE. As such you should be able to get to it and set the locale for the JSTL tags by using the following:

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

Hope that works for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜