SeamFramework.orgCommunity Documentation
There are currently two ways to create a message within the module.
The first would mostly be used when you don't want to add the generated message directly to the UI, but want to log it out, or store it somewhere else
@Inject
private MessageFactory factory;
public String getMessage() {
MessageBuilder builder = factory.info("There are {0} cars, and they are all {1}; {1} is the best color.", 5, "green");
return builder.build().getText();
}
The second is to add the message to a list that will be returned to the UI for display.
@Inject
private Messages messages;
public void setMessage() {
messages.info("There are {0} cars, and they are all {1}; {1} is the best color.", 5, "green");
}
Either of these methods supports the four message levels which are info, warning, error and fatal.
Both MessageFactory and Messages support four ways in which to create a Message:
Examples for each of these are:
messages.info("Simple Text");
messages.info("Simple Text with {0} parameter", 1);
messages.info(new BundleKey("org.jboss.international.seam.test.TestBundle", "key1"));
messages.info(new BundleKey("org.jboss.international.seam.test.TestBundle", "key2"), 1);
The examples in the previous section on how to create a message from a properties file made the assumption that you had already created it! Now we tell you how to actually do that.
When creating a BundleKey
in the previous section, we were passing it a bundle name of
"org.jboss.international.seam.test.TestBundle". This name is essentially the path to the properties file!
Let me explain. As we all know properties files need to be on the classpath for our code to find them, so
"org.jboss.international.seam.test.TestBundle" is telling our code that on the classpath there is a
TestBundle.properties
file located at a path of org/jboss/international/seam/test
.
To create a property file for another language, it's simply a case of appending the name of the locale to
the end of the file name. Such as TestBundle_fr.properties
for French or
TestBundle_en_US.properties
for American English.