Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: JSTL and messageResource settings

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Roeselare, Belgium
    Posts
    16

    Default

    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.
    Pieter Coucke
    Onthoo.com

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default Re: JSTL and messageResource settings

    Quote 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.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  4. #4
    Join Date
    Dec 2005
    Posts
    7

    Default

    Quote 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>

  5. #5
    Join Date
    Dec 2005
    Posts
    15

    Default 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.

  6. #6
    Join Date
    Mar 2006
    Location
    New York City
    Posts
    16

    Talking 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>.

  7. #7
    Join Date
    Jul 2006
    Posts
    13

    Default 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.

  8. #8

    Smile

    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>

  9. #9
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    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 at 10:38 AM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  10. #10

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •