Java Reference
In-Depth Information
Download email_20/res/StripesResources.properties
stripesbook.action.ContactFormActionBean.contactSaved=\
{0} has been saved.
stripesbook.action.ContactFormActionBean.actionCancelled=\
Action cancelled.
Download email_20/res/StripesResources_fr.properties
stripesbook.action.ContactFormActionBean.contactSaved=\
{0} a \u00e9t\u00e9 enregistr\u00e9(e).
stripesbook.action.ContactFormActionBean.actionCancelled=\
Action annul\u00e9e.
Notice the two ways in which information messages differ from error
messages:
• Since there is no field name and value entered by the user, tokens
for replacing parameters in the text start at {0} .
• Stripes doesn't add the action bean class name prefix, so the
resource bundle key is just used as is. We're adding the class
name prefix ourselves so that the keys consistently use the same
pattern as for error messages. Doing this is, of course, completely
optional.
Translating Free-Form Text
What's left to translate is the free-form text. Stripes stays out of this one
because the JSTL already provides the <fmt:message> tag for retrieving
text from a resource bundle. For example, <fmt:message key="hello"/> dis-
plays the text for the hello key. You can also store the text in a variable
with the var= attribute, as in <fmt:message key="hello" var="greeting"/> , and
display it later in the JSP with ${greeting} .
The JSTL, however, doesn't know that we're using StripesResources . Add
the following context parameter at the top of web.xml to tell the JSTL to
use StripesResources as the default resource bundle:
Download email_20/web/WEB-INF/web.xml
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value> StripesResources </param-value>
</context-param>
You can now use the <fmt:message> tag with corresponding key-value
pairs in the StripesResources resource bundle. As with the LocalizableMes-
sage class, you choose arbitrary keys, and they are used as is, without
 
 
Search WWH ::




Custom Search