December 8, 2005

Divide and rule - use multiple resource bundles

Too tired of searching through the long struts resource bundles file for the text you added? Get a new resource file for your module. All you need is to modify the struts-config.xml in the following manner:

<message-resources

parameter=" com.text.sachin.msgText "

key="msgText">

</message-resources>

<message-resources

parameter=" com.text.sachin.pageText "

key="pageText">

</message-resources>

On application startup, Struts creates a runtime representation of the message resources and stores it in the servlet context.

Note: If the properties file was located in /WEB-INF/classes/com/text/sachin/msgText.properties, you would set up the message resources element as follows:

<message-resources

parameter="com.text.sachin.msgText"/>

Use “bundle” parameter in “bean:message” tag to identify the file having the properties.

<bean:message bundle="msgText" key="msgText.welcome"/>

I’ll try to upload files with working example to illustrate this technique of struts. Post me in case you need help.