PDA

View Full Version : differences between spring:message and fmt:message



sjivan
Sep 22nd, 2004, 07:04 AM
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

davison
Sep 22nd, 2004, 07:08 AM
a description of the taglib is here:
http://www.springframework.org/docs/taglib/index.html

hth,

sjivan
Sep 22nd, 2004, 07:20 AM
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

sjivan
Oct 30th, 2004, 05:36 AM
Can anyone clarify the differences between spring:message and fmt:message? And which is preferred when using Spring MVC?

Thanks,
Sanjiv

milosh
Jan 5th, 2005, 12:07 AM
I would also like to hear more specific explanation on differences between those two tags.

Thanks,
Milosh

dadams
Jan 5th, 2005, 03:38 PM
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 (http://www.springframework.org/docs/reference/mvc.html#mvc-localeresolver) 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

milosh
Jan 5th, 2005, 03:48 PM
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,

dju`
May 19th, 2009, 02:56 AM
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.

ctapobep
May 19th, 2009, 03:03 AM
And what about view resolvers? Books say that if we don't specify something like this

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>in view resolver, localization of JSTL tags will not work.

dju`
May 19th, 2009, 03:35 AM
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.