Announcement Announcement Module
Collapse
No announcement yet.
Cannot get fmt:message & ${} to work in one of the proje Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot get fmt:message & ${} to work in one of the proje

    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

  • #2
    Make sure you have a messageSource bean defined and "heading" and "user.id" keys exist in your messages.properties file.

    Code:
        <!-- Load WEB-INF/classes/messages.properties for i18n messages using JSTL's fmt tag -->    
        <bean id="messageSource" 
            class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename"><value>messages</value></property>
        </bean>

    Comment


    • #3
      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...

      Comment


      • #4
        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

        Comment


        • #5
          jstl and the ??value??

          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!

          Comment


          • #6
            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

            Comment


            • #7
              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

              Comment


              • #8
                Need context-params in web.xml

                Do you have the necessary context-params in your web.xml?

                Code:
                     <!-- 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>

                Comment


                • #9
                  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!

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      Originally posted by mraible
                      Make sure you have a messageSource bean defined and "heading" and "user.id" keys exist in your messages.properties file.

                      Code:
                          <!-- Load WEB-INF/classes/messages.properties for i18n messages using JSTL's fmt tag -->    
                          <bean id="messageSource" 
                              class="org.springframework.context.support.ResourceBundleMessageSource">
                              <property name="basename"><value>messages</value></property>
                          </bean>
                      Can you change the location of messages.properties?

                      Sami

                      Comment


                      • #12
                        Originally posted by samilocale
                        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?

                        Comment


                        • #13
                          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

                          Comment


                          • #14
                            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, which is an Eclipse-ready project. Here's a howto for setting it up in Eclipse:

                            http://jroller.com/page/raible?ancho...ers_in_eclipse

                            The "myusers" application in the above URL is based on Equinox.

                            Hope this helps,

                            Matt

                            Comment


                            • #15
                              Originally posted by mraible
                              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, which is an Eclipse-ready project. Here's a howto for setting it up in Eclipse:

                              http://jroller.com/page/raible?ancho...ers_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

                              Comment

                              Working...
                              X