Announcement Announcement Module
Collapse
No announcement yet.
JSTL and messageResource settings Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSTL and messageResource settings

    I am working on a Spring + Struts application and I am trying to set-up the Spring Resource Bundle.

    Here is my applicationContext entry:
    Code:
       <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
        <property name="basenames"> 
          <list> 
            <value>WEB-INF/messages</value>  
          </list> 
        </property> 
      </bean>
    I have a resource file called messages.properties in the WEB-INF directory.

    When I use jstl tags (ex: fmt:message) in my jsps, I still get the ???messagekey??? values.

    Am I missing something?

    Thanks.

  • #2
    I had something similar with ReloadableResourceBundleMessageSource in an earlier release of Spring, but using ResourceBundleMessageSource worked for me. I don't know if this is changed in the current release.

    Comment


    • #3
      Re: JSTL and messageResource settings

      Originally posted by AymericAlibert

      I have a resource file called messages.properties in the WEB-INF directory.

      When I use jstl tags (ex: fmt:message) in my jsps, I still get the ???messagekey??? values.

      Am I missing something?

      Thanks.
      Make sure you use JstlView (or TilesJstlView when using Tiles) when using Jstl, not InternalResourceView.

      Comment


      • #4
        Originally posted by Colin Sampaleanu
        Make sure you use JstlView (or TilesJstlView when using Tiles) when using Jstl, not InternalResourceView.
        Can you clarify? Is this wrong?

        <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
        <property name="viewClass">
        <value>org.springframework.web.servlet.view.JstlVi ew</value>
        </property>
        <property name="prefix">
        <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
        <value>.jsp</value>
        </property>
        </bean>

        Comment


        • #5
          Spring:message

          I solved it a month ago.

          When you are using ResourceBundleMessageSource a want use jstl tag fmt:message it is necessary to set message resource for fmt explicitly on your view:
          Code:
          <fmt:setBundle basename="WEB-INF/messages"/>
          Btw...I have my message resource in classpatch ("classes" folder) so in my applicationContext.xml i have only
          Code:
          <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
              <property name="basenames"> 
                <list> 
                  <value>messages</value>  
                </list> 
              </property> 
            </bean>
          so my view (jsp) looks like:

          Code:
          <fmt:setBundle basename="messages"/>
          Code:
          <fmt:message key="page.title"/>
          and it works...

          but...better solution is to use
          Code:
          <spring:message code="page.title"/>
          is runs without need of explicit setting like fmt does...

          At the and a little snippet from spring:message documentation


          The spring:message tag provides you with internationalization support using Spring's MessageSource concept. The MessageSource is an interface providing functionality for retrieving messages. It closely resembles JSTL's fmt:message-tag, however, the MessageSource classes can be integrated with the Spring context. Also, the spring:message- tag, works with the locale support that comes with Spring.
          Regards an HTML escaping setting, either on this tag instance, the page level, or the web.xml level. Can also apply JavaScript escaping.

          If "code" isn't set or cannot be resolved, "text" will be used as default message. Thus, this tag can also be used for HTML escaping of any texts.

          Comment


          • #6
            Same problem, solved

            I encountered the same problem when using TilesView as my viewResolver. Changing it to TilesJstlView resolved the problem while still using JSTL version 1.1.2 without using <fmt:setBundle>.

            Comment


            • #7
              Vlasta's solution works, thank you

              but in the article "spring mvc step by step", the jsp files don't explicitly set message source for fmt, they still works fine.

              Comment


              • #8
                I encountered the same problem when using TilesView as my viewResolver. Changing it to TilesJstlView resolved the problem while still using JSTL version 1.1.2 without using <fmt:setBundle>.
                thanks jongraf, your suggestion helped me to solve my problem. thanks alot.

                For others, I was facing the same problem.
                I was using Tiles and replacing the TilesView to TilesJstlView in view.properties file.

                Code:
                Welcome.class=org.springframework.web.servlet.view.tiles.TilesJstlView
                Welcome.url=Welcome
                Configuration looked like

                Code:
                <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
                		<property name="basename" value="messages"></property>
                	</bean>
                
                	<bean id="tilesConfigurer"
                		class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
                		<property name="factoryClass" value="org.apache.struts.tiles.xmlDefinition.I18nFactorySet"></property>
                		<property name="definitions">
                			<list >
                				<value>/WEB-INF/defs/tiles-def.xml</value>
                			</list>
                		</property>
                	</bean>
                
                	<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
                    	<property name="basename" value="views"></property>
                	</bean>

                Comment


                • #9
                  Hello AymericAlibert
                  all that you need is this

                  Code:
                  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                  	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /><!--  avoid '???' -->
                      	<property name="prefix" value="/WEB-INF/jsp/" />
                      	<property name="suffix" value=".jsp"/>
                  </bean>
                  	
                  
                  <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
                  	<property name="cacheSeconds" value="5"/>
                  	<property name="basename" value="WEB-INF/interproperties/messages"/>
                  </bean>
                  i had the same problem , thats is enough

                  I am working on a Spring + Struts application and I am trying to set-up the Spring Resource Bundle.
                  spring alone or spring mvc???
                  if is only spring with struts why are you using the messages ???

                  i do think that Spring Resource Bundle is for "spring mvc"

                  regards
                  Last edited by dr_pompeii; Mar 17th, 2007, 11:38 AM.

                  Comment


                  • #10
                    I m finding a problem in the validationutil , when using this errors.rejectvalue(fieldname,"label.firstname",def aultMessageSourceResolvableObj, errormsg).

                    where would the resource bundle (containing label.firstname) would be specified?

                    Im getting null pointer exception in jsp, as its not able to locate the bundle

                    Comment


                    • #11
                      Re: Colin Sampaleanu

                      Originally posted by Colin Sampaleanu View Post
                      Make sure you use JstlView (or TilesJstlView when using Tiles) when using Jstl, not InternalResourceView.
                      Thanks!
                      <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
                      <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
                      <property name="prefix" value="/WEB-INF/jsp/"/>
                      <property name="suffix" value=".jsp"/>
                      </bean>

                      jstl tag <fmt:message>home.greeting</fmt:message>
                      Now it works!

                      Comment

                      Working...
                      X