Announcement Announcement Module
No announcement yet.
Jstl localization in Struts2 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jstl localization in Struts2

    Hi guys -
    I'm having an issue using JSTL's <fmt:message ..> tag within Struts2.

    I have set up multiple MessageResources using

    	<bean id="messageSource" class="">
    	    <property name="basenames"> 
    	    <property name="cacheSeconds" value="7200"/>
    and can successfully localize a message from these bundles in my main body of code using

    ctx.getMessage("", new Object[]{}, Locale.ENGLISH)
    where 'ctx' is the ApplicationContext received via implementing the ApplicationContextAware interface. Up to here, everything is great.

    However, JSTL's <fmt:message ..> tag is unable to locate the resource bundle(s). I searched around and found Juergen's integration code in and around
    , and added a viewResolver to my appContext

     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
       <property name="prefix" value="/WEB-INF/pages/"/>
       <property name="suffix" value=".jsp"/>
    based on, but to no effect. There are no other ViewResolvers defined in my context.

    The viewResolver may be doing something like executing JstlUtils.exposeLocalizationContext(...), which seems to be the missing link here, but I haven't had luck getting either the viewResolver to be recognized, or doing this call explicitly in an Interceptor or somewhere (for lack of a RequestContext).

    One clue -- using the various Struts tags available for localization only succeeds for the <s:i18n> tag which allows the bundle name to be specified explicitly
         <s:i18n name="form">
            <s:text name=""/>
    I could just use this tag, but that would require a slew of code changes.

    Any ideas or suggestions? Thanks -