Announcement Announcement Module
Collapse
No announcement yet.
Jstl localization in Struts2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

    Code:
    	<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    	    <property name="basenames"> 
    	       <list>
    	           <value>classpath:/form</value>
                      <value>classpath:/ApplicationResources</value>
               </list>
            </property>
    	    <property name="cacheSeconds" value="7200"/>
    	</bean>
    and can successfully localize a message from these bundles in my main body of code using

    Code:
    ctx.getMessage("q.client.name.first", 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
    Code:
    org.springframework.web.servlet.support.JstlUtils
    , and added a viewResolver to my appContext

    Code:
     <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"/>
     </bean>
    based on http://static.springsource.org/sprin.../JstlView.html, 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
    Code:
         <s:i18n name="form">
            <s:text name="q.client.name.first"/>
         </s:i18n>
    I could just use this tag, but that would require a slew of code changes.

    Any ideas or suggestions? Thanks -
    Kent
Working...
X