Announcement Announcement Module
Collapse
No announcement yet.
differences between spring:message and fmt:message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • differences between spring:message and fmt:message

    The spring:message tag documentation talks about some differences between fmt:message and spring:message yet fmt:message works using the ResourceBundleMessageSource that is configured in the spring application context. What are the behavioral differences between the two? Is there any advantage of using spring:message over fmt:message?

    Thanks,
    Sanjiv

  • #2
    a description of the taglib is here:
    http://www.springframework.org/docs/taglib/index.html

    hth,

    Comment


    • #3
      I actually read that.

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

      The first point being - "MessageSource classes can be integrated with the Spring context". As I mentioned, after configuring the MessageSource in my Spring application context, fmt:message is able to successfully lookup the resource bundle keys. So after configuring a message source in my app context, what would the advantage be of using spring:message over the standard fmt:message in my JSP's?

      I also don't fully understand specifically what spring locale support they are referring to when they say that "the spring:message- tag, works with the locale support that comes with Spring". Can you give me an example where spring:message behaves differently or is more powerful compared to fmt:message.

      Thanks,
      Sanjiv

      Comment


      • #4
        Can anyone clarify the differences between spring:message and fmt:message? And which is preferred when using Spring MVC?

        Thanks,
        Sanjiv

        Comment


        • #5
          I would also like to hear more specific explanation on differences between those two tags.

          Thanks,
          Milosh

          Comment


          • #6
            Spring gives more flexibility in how the locale for messages is resolved. I am pretty sure that the fmt:message tag uses request.getLocale() to establish the locale for messages. Check here for how a DispatcherServlet locale resolver can be set up to allow other methods of setting the locale (like using a cookie or session setting rather than browser default). I think using fmt:message is the equivalent of using the Spring AcceptHeaderLocaleResolver.

            Hope that helps,
            Derek

            Comment


            • #7
              I was thinking the same thing. I was actually a bit suspicious when I saw that all Spring examples are using fmt:message rather than spring:message. I didn't have enough time to check source code for fmt:message and spring:message. I will try to do that ASAP. Let you know the conclusion.

              Thanks for the reply,

              Comment


              • #8
                I can understand fmt:message doesn't use the configured Spring locale resolver and use HTTP header resolution instead, but why/how can it use the configured ResourceBundleMessageSource bean ? I've tested fmt:message with this bean but without defining and javax.servlet.jsp.jstl.fmt.localizationContext in the web.xml file, and it works... can someone explain me how it is possible ? Thanks.

                Comment


                • #9
                  And what about view resolvers? Books say that if we don't specify something like this
                  Code:
                  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
                  in view resolver, localization of JSTL tags will not work.

                  Comment


                  • #10
                    You're right, the JstlView and JstlUtils classes do all the magic by setting a LocalizationContext for JSTL tags to work. And it also sets the locale ! That is : fmt:message tags will use the declared localeResolver (cookie, session... not just HTTP header) !

                    The other differences I see between spring:message and fmt:message is that :
                    * spring:message can use a default message if the specified key is not found in the bundle,
                    * spring:message takes arguments for parametrized messages in the tag itself (no need to embed fmt: param tags),
                    * spring:message can perform HTML and Js escaping.
                    Last edited by dju`; May 19th, 2009, 04:02 AM.

                    Comment

                    Working...
                    X