As an alternative to I have been developing a new component that can be used to expose messages from any Spring , as well as offering a few other advantages.
The new component is a drop-in replacement for .
<s:messageSource source="#{messageSource}" var="messages"/>
<p>
<h:outputText value="#{messages.hello}"/>
</p>The attribute can be any EL expression that resolves to a instance. If the source is not specified the Spring will be used. The attribute is the name of the variable that will be used to access the messages.
If you make reference to message in your XHTML that you have forgotten to define you will either see a warning message (when in development) or an exception will be thrown (when in production).
As with standard JSF, your messages and include place-holders for use with
pages.message.simple.welcome=Welcome to {1} with {0}<h:outputFormat value="#{messages.welcome}">
<f:param value="Spring"/>
<f:param value="JSF"/>
</h:outputFormat>The tag is a little bit verbose, so for convenience, Spring messages can be used as s. This allows you to reference place-holders in a much more concise way:
<h:outputText value="#{messages.welcome['Spring']['JSF']}"/>The same syntax allows you to map Java objects to messages. By default objects are mapped by building a message key from class name. For example, the following class:
package org.example;
public class ExampleObject {
}Can be referenced in JSF:
<h:outputText value="#{messages[exampleInstance]}"/>Resolving to the following message:
org.example.ExampleObject=example
For enum objects the message key includes the enum name as well as the class:
package org.example;
public enum ExampleObject {
ONE, //mapped to message key org.example.ExampleObject.ONE
TWO //mapped to message key org.example.ExampleObject.TWO
}Object messages can also make reference to properties that should form part of the message:
org.example.PersonName=Name is {first} {last}
...
package org.example;
public class PersonName {
...
public String getFirst() {...}
public String getLast() {...}
}You can also define your own object message strategies by using a message source that implements the interface.
If you want to check out any of this code take a look at the and packages from the GitHub Project.
Reference: Integrating Spring & JavaServer Faces : Internationalization and Localization from our JCG partner Phillip Webb at the Phil Webbβs Blog blog.
Thank you!
We will contact you soon.
Phillip WebbJune 6th, 2012Last Updated: October 22nd, 2012

This site uses Akismet to reduce spam. Learn how your comment data is processed.