Java Reference
In-Depth Information
<fmt:setBundle basename="${actionBean.class.name}"/>
Every page already uses
taglibs.jsp
, so just like that, we've set the bundle
globally. Now the JSTL will dynamically use the action bean class as a
base name for its resource bundle. That's it—we don't even need the
javax.servlet.jsp.jstl.fmt.localizationContext
context parameter in
web.xml
in
this case.
With this nifty maneuver, the <fmt:message> keys in the JSPs don't
need a prefix. For example, in the Login page, we now have this:
<fmt:message var="title" key="title"/>
<s:layout-render name="/WEB-INF/jsp/common/layout_main.jsp"
title="${title}">
<s:layout-component name="body">
<p><fmt:message key="pleaseLogin"/>
:
</p>
<!-- ... -->
<s:link beanclass="stripesbook.action.RegisterActionBean">
<fmt:message key="register"/>
</s:link> <fmt:message key="toCreateAnAccount"/>
.
</s:layout-component>
</s:layout-render>
Since the page is associated to
stripesbook.action.LoginActionBean
, that
becomes the resource bundle for the localized text:
title=Login
pleaseLogin=Please login
register=Register
toCreateAnAccount=to create an account
title=Identification
pleaseLogin=Veuillez vous identifier
register=Enregistrez-vous
toCreateAnAccount=pour cr\u00e9er un compte
Very clean. The keys are concise, and the resources are grouped to-
gether with the action bean class in matching .
properties
files.
The only exception to this resource bundle pattern is using
StripesRe-
sources
for free-form text not associated with a specific action bean,
such as in the layout JSPs. In those cases, add
<fmt:setBundle base-
Search WWH ::
Custom Search