View Full Version : Cannot get fmt:message & ${} to work in one of the proje
theone
Aug 22nd, 2004, 09:44 PM
Hi,
I've two spring web apps, one works fine and the other app doesn't seem to be getting the values from messages.properties and not getting the values from the variables through jstl. they are both implemented the same way and the same jar dependencies.
I'm not getting any output with fmt:message and ${}
The output show up on the view as
I'm using these tags
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<fmt:message key="heading"/>
I get ???heading???
<c:forEach var="user" items="${model.users}" varStatus="status">
<fmt:message key="user.id"/>
I get
???user.id???
???user.id???
???user.id???
...
...
It's looping through the list with the correct number of records as the database (12 records total)
If I tried to use
<%@ taglib uri="http://java.sun.com/jstl/core_rt prefix="c" %> instead
It only shows one record with ???user.id???
Can someone tell me what am I missing?
Thank you
mraible
Aug 23rd, 2004, 11:31 AM
Make sure you have a messageSource bean defined and "heading" and "user.id" keys exist in your messages.properties file.
<!-- Load WEB-INF/classes/messages.properties for i18n messages using JSTL's fmt tag -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename"><value>messages</value></property>
</bean>
theone
Aug 23rd, 2004, 12:03 PM
Matt,
I was following chapter 4 and am using websphere studio app develop 5.1.2. I think it's the common validator is not working the way it supposed to...
mraible
Aug 23rd, 2004, 12:11 PM
It's an issue with WebSphere - read more at http://byandlarge.net/thebitterend/archives/000171.html.
Basically, you need to rename messages.properties to something else - like mymessages.properties - and change the basename in action-servlet.xml.
HTH,
Matt
Naruto-fan
Nov 22nd, 2004, 10:17 PM
Hello!
I have been combing through this forum and Sun's site on JSTL tags, for the answer to my question. I copied EXACTLY the instructions from the MVC tutorial and I still can't get my <fmt:message > tag to work corrrectly. I always get the ??value?? in my view.
(using Tomcat 5.0.25, spring 1.1, jstl.jar that came with the spring distribution)
I keep getting this error message: "2004-11-22 18:23:16,828 WARN [org.springframework.context.support.ResourceBundle MessageSource] - ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en_US"
I have the message.properties file in: /WEB-INF/classes/message.properties
in the action-servlet.xml I used the ResourceBundleMessageSource.
I just can't get this bird to fly. Any suggestions on the culprit? Maybe there is something in another configuration that was assumed but not said?
Thanks in advanced!
jfd
Nov 23rd, 2004, 12:43 AM
if you put sring tags there and I assume you did, then this should work for you:
<spring:message code="${msgName}">
But I have another issue too, that the following is not working. I cannot get the variable anotherVar in this case.
<spring:message code="${msgName}">
var="anotherVar" scope="request"/>
<c:out value="${anotherVar}"/>
Thanks a lot.
jfd
Naruto-fan
Nov 24th, 2004, 01:20 AM
Thanks jfd!
I'll give your suggestion a whirl. I still for the life of me couldn't get the <fmt:message> to work....
Thanks
mraible
Nov 24th, 2004, 09:08 AM
Do you have the necessary context-params in your web.xml?
<!-- Define the basename for a resource bundle for I18N -->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
<!-- Fallback locale if no bundles found for browser's preferred locale -->
<!-- Force a single locale using param-name 'javax.servlet.jsp.jstl.fmt.locale' -->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
<param-value>en</param-value>
</context-param>
Naruto-fan
Nov 24th, 2004, 04:39 PM
yup,
I did try it with the <context-param> tags. No go. I think I am missing something more basic.
Time for a clean slate and the most minimal config.
Thanks for the suggestions! The best learning is done is when you are counfounded by the solution. So much for my assumption that this should be easy (it is always easy, once you know how!).
Mahalo!
jfd
Nov 30th, 2004, 02:00 AM
I finally found the problem source. it is due to the newest jstl or may be there are some special configurations for the latest ones that I did not do? Unfortunately the JSTL forum is closed. So I switch back to 1.0 and it is work now.
So if you are using the 1.1.2, try using the old version.
Hope this helps.
JFD
samilocale
Jun 3rd, 2005, 04:19 PM
Make sure you have a messageSource bean defined and "heading" and "user.id" keys exist in your messages.properties file.
<!-- Load WEB-INF/classes/messages.properties for i18n messages using JSTL's fmt tag -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename"><value>messages</value></property>
</bean>
Can you change the location of messages.properties?
Sami
mraible
Jun 3rd, 2005, 08:45 PM
Can you change the location of messages.properties?
Yes, but putting it in WEB-INF/classes is the standard location for most webapps. Where would you rather put it?
samilocale
Jun 6th, 2005, 09:00 AM
I apologize if my question upsets those who are advocates of the framework. I don't mean to question the standard approach and I have no idea this is the standard approach. As a matter of fact, I'm just a newbie who switched from .net to j2ee six months ago. Although I'm not new to java, the concept of developing java using webapps is still new to me.
The reason I asked the question is because I couldn't figure out how to display /web-inf/classes under project hierarchy in eclipse, and because of that, I have to do a file-->open external file every time I want to edit message.properties.
I'm open to any suggestions.
Sami
mraible
Jun 6th, 2005, 10:25 AM
It sounds like a problem with your project setup to me. Are you using any specialized project structure from a plugin or something? You could try downloading Equinox (http://equinox.dev.java.net), which is an Eclipse-ready project. Here's a howto for setting it up in Eclipse:
http://jroller.com/page/raible?anchor=setup_myusers_in_eclipse
The "myusers" application in the above URL is based on Equinox.
Hope this helps,
Matt
samilocale
Jun 8th, 2005, 07:56 AM
It sounds like a problem with your project setup to me. Are you using any specialized project structure from a plugin or something? You could try downloading Equinox (http://equinox.dev.java.net), which is an Eclipse-ready project. Here's a howto for setting it up in Eclipse:
http://jroller.com/page/raible?anchor=setup_myusers_in_eclipse
The "myusers" application in the above URL is based on Equinox.
Hope this helps,
Matt
I have the myeclipse plugin installed. Will that cause problems with equinox and spring ide? Also, I'm now getting "package org.apache.taglibs.standard.tag.el.cor does not exist", but I'm still able to deploy my project successfully. Do I need to include a tld file for jstl?
Sami
mraible
Jun 8th, 2005, 08:23 AM
I have the myeclipse plugin installed. Will that cause problems with equinox and spring ide? Also, I'm now getting "package org.apache.taglibs.standard.tag.el.cor does not exist", but I'm still able to deploy my project successfully. Do I need to include a tld file for jstl?
Are you getting this at build time from your IDE? Or after you deploy? If you're getting it at build-time, it's likely you have to register the TLD (or something similar) with MyEclipse.
Asya
Jun 8th, 2005, 08:55 AM
I might be way off but you might want to change the name of the file which contains your messages - it might be related to Websphere, the way it loads classes and the fact that there is another messages.properties file in the Websphere classpath
samilocale
Jun 9th, 2005, 11:22 AM
I have the myeclipse plugin installed. Will that cause problems with equinox and spring ide? Also, I'm now getting "package org.apache.taglibs.standard.tag.el.cor does not exist", but I'm still able to deploy my project successfully. Do I need to include a tld file for jstl?
Are you getting this at build time from your IDE? Or after you deploy? If you're getting it at build-time, it's likely you have to register the TLD (or something similar) with MyEclipse.
It's resolved, but I'm still not sure what caused it. The problem occurred at build time, so I followed your advice and examine the myeclipse xml catalog to make sure that jstl is up-to-date, and it was. Then I thought maybe if I go into project properties and add jstl.jar and standard.jar into the java build path, the errors would go away, and it did!
I understand that those "tag does not exist" errors would show if I don't add the correct jars. What I don't understand is why this is neccessary when I explicitly added jstl support when I created this project. I try to backtrack what I did and remember that I had those two jars replaced by the ones that came with spring. Can that be it?
samilocale
Jun 9th, 2005, 11:39 AM
I might be way off but you might want to change the name of the file which contains your messages - it might be related to Websphere, the way it loads classes and the fact that there is another messages.properties file in the Websphere classpath
I'm using weblogic 8.1. Up until yesterday, I was saving messages.properties in /web-inf/classes and referenced it with a resourcebundlemessagesource. While I was perusing the spring live blog, someone (matt?) suggested using the following instead:
<bean id="messageSource" class="org.springframework.context.support.ReloadableReso urceBundleMessageSource">
<property name="basename"><value>/WEB-INF/messages</value></property>
</bean>
I thought I would share this because this is really cool. I'm thinking about creating a rss feed using this. What do y'all think?
samilocale
Jun 10th, 2005, 08:36 AM
Getting ahead of myself here. I should've look through all the spring examples. It turns out there is a newsfeed object in spring. Take a look at this from the tiles sample:
<bean id="feedConfigurer" class="org.springframework.samples.tiles.NewsFeedConfigur er">
<property name="feeds">
<props>
<prop key="theserverside">http://www.theserverside.com/rss/theserverside-1.0.rdf</prop>
<prop key="slashdot">http://slashdot.org/slashdot.rss</prop>
<prop key="javablogs">http://www.javablogs.com/ViewDaysBlogs.action?view=rss</prop>
</props>
</property>
</bean>
lathapss
May 24th, 2007, 02:34 PM
do check the file as 'messages.properties'
<bean id="messageSource" class="org.springframework.context.support.ReloadableReso urceBundleMessageSource">
<property name="basename"><value>/WEB-INF/messages</value></property>
</bean>
apts
Feb 26th, 2008, 12:49 AM
message.properties fmt
Above mentioned way works fine for me.
Note that messages.properties file shoul be saved in WEB-INF and not in classes as we gave path to WEB-INF/messages in the beans id in -servlet.xml file.
clausia
Jul 16th, 2008, 09:37 AM
<c:forEach var="user" items="${model.users}" varStatus="status">
<fmt:message key="${user.id}"/>
Hope this helps...
stanicmail
Sep 26th, 2008, 09:39 PM
I am new to spring and facing the same problem and try all the way in this forum but no one work for me. because i have stupid mistake. haha. finally i notice that my file extensions was hide(default) so the "messages.properties" actually is "messages.properties.txt". then i rename it to and it work.haha.
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.