aspose file tools*
The moose likes Struts and the fly likes serveral ApplicationResources .properties for one project? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "serveral ApplicationResources .properties for one project?" Watch "serveral ApplicationResources .properties for one project?" New topic
Author

serveral ApplicationResources .properties for one project?

Feda Bashbishi
Greenhorn

Joined: Feb 25, 2004
Posts: 7
I am part of a group who is using Struts to build a project for San Jose State University. Every member has his own module to work on and everyone has his own ApplicationResources .properties file.
My Q is :
What should I do to maintain separate properties files and yet they are all integrated into the project?


fb
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Feda,
Declare all of the message resources (properties file) in the struts-config.xml as follows:
<message-resources parameter="mybank.example.DefaultMsgResource"
null="false"/>
<message-resources parameter="mybank.example.AltMsgResource"
null="false" key="bundle.alt" />
<message-resources parameter="mybank.example.ErrorMsgResource"
null="false" key="bundle.error" />
The first is the default resource bundle.
Elsewhere in your code access the bundle as follows:
To use the default bundle, your <bean:message> would look like:
<bean:message key=�msg.key� />
To access the messages from other bundles specify the bundle name as follows:
<bean:message key=�msg.key� bundle=�bundle.alt� />
Hope that helps.
[OT]: Also consider splitting your struts application into multiple modules - each having its own struts config file.


Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
Feda Bashbishi
Greenhorn

Joined: Feb 25, 2004
Posts: 7
Thanks Srikanth that was helpful.
- What you mentioned was for the JSPs, what can I use to call those different msgs from my Action and ActionForm classes? How can I differentiate between the msgs in the different properties files?

- About having different Config-xml files, I am assuming I should define all of them in the web.xml file, such as:
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config-default.xml</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config-module2.xml</param-value>
</init-param>
.
.
.
?
Regards,
Bob Zyeruncle
Greenhorn

Joined: Mar 16, 2004
Posts: 1

- About having different Config-xml files, I am assuming I should define all of them in the web.xml file, such as:
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config-default.xml</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config-module2.xml</param-value>
</init-param>

Hi Feda,
Yes, that's basically it. There are some caveats: You can't use wildcard mapping (only directory mapping) when using modules, and you probably should name the configs to match the module names a bit better.
An easier, single-module/multiple-config approach is to add each to the web.xml in a comma-separated list:

HTH,
Bob
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: serveral ApplicationResources .properties for one project?