Java Reference
In-Depth Information
stripesbook.action.ContactFormActionBean.contact.firstName
MyResourceBundle
bundle
name
key
stripesbook.action.ContactFormActionBean
contact.firstName
stripesbook/action/ContactFormActionBean.properties
contact.firstName=First name
Figure 11.5: Using a custom resource bundle
name of the action bean. For example, the resource bundle files for the
following:
stripesbook.action.ContactFormActionBean
would look like this:
stripesbook/action/ContactFormActionBean.properties
stripesbook/action/ContactFormActionBean_fr.properties
As usual, the files would have to be found in the classpath, such as
under the WEB-INF/classes directory.
The trick here is that the name of the resource bundle has to be deter-
mined “on the fly” according to the class name at the beginning of the
key. We need a custom ResourceBundle ( MyResourceBundle , say) that looks
at the key, extracts the class name and uses it as a resource bundle
name, and looks up the value using the rest of the key, as illustrated
in Figure 11.5 .
 
 
 
Search WWH ::




Custom Search