aspose file tools*
The moose likes Struts and the fly likes Multiple properties files 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 "Multiple properties files" Watch "Multiple properties files" New topic
Author

Multiple properties files

RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi all,

I wanted to know if I can use multiple properties file in a Struts application? Please dont confuse it with i118n. i want to access 5 differnt properties files for the same language.
I have 5 modules and have 5 struts-config files, which have entries in the web.xml. It works fine. But if i have differnt properties file it doesnt take the file. Any help would be appreciated.
Thanks in advance.

Regards,
Roshani


Regards,<br />Roshani
Vijendra Babar
Greenhorn

Joined: Jul 28, 2006
Posts: 18
Following code need to be entered in your struts-config.xml

<message-resources parameter="ApplicationResourcesOne" null="true"/>
<message-resources key="alternate" parameter="ApplicationResourcesTwo" null="true"/>

Hope so this will help you.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One more thing that needs to be mentioned is that in Vijendra's example, you would need to specify bundle="alternate" in your <bean:message> tag in order to tell struts to use that resource bundle rather than the default one with no "key" specified.


Merrill
Consultant, Sima Solutions
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Thanks Vijendra and Merrill,
I would like some more clarification from your side.
1) Do I have make this entry into all the struts-config.xml ( I have 5 different struts-config.xml for all different modules that too in different directories).
Struts-config-module1.xml
<message-resources parameter="ApplicationResourcesOne" null="true"/>
<message-resources key="alternate" parameter="ApplicationResourcesTwo" null="true"/>

Struts-config-module2.xml
<message-resources parameter="ApplicationResourcesOne" null="true"/>
<message-resources key="alternate3" parameter="ApplicationResourcesThree" null="true"/>

2) For the <bean:write> do i have to write as:
<bean:message key="SearchAddress.search.button.label" bundle="alternate" />

For Test.jsp:

For acessing a properties file in ApplicationResourcesOne
<bean:message key="SearchAddress.search.button.label" bundle="alternate" />
For acessing a properties file in ApplicationResourcesThree
<bean:message key="SearchAddress.add.button.label" bundle="alternate3" />

Thus by using the above, will I be able to get the 2 differnt labels( from differnt properties file) in the same JSP?

Thanks in advance.
Regards,
Roshani
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It's important to understand that a configuration file for a specific module only applies to that module. So, whatever module the current JSP is in, you only have access to that module's message resources.

In your example, then, the answer is no, you won't be able to get both resources. If the JSP is in Module 1, you have access to the "alternate" bundle. If it's in Module 2, you have access to "alternate3". In neither case do you have access to both.

If you want access to both, you will have to declare both alternate and alternate3 in the module that contains the JSP.
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Merrill,

Thanks a lot for your prompt reply. It was so urgently required.It makes lot of sense what you wrote.

To sum up i would say that we cannot have multiple properties files in different modules and with the JSPs (from all modules) access all the different properties files. we cannot do that.

If I want to I would have to duplicate the properties files in all the modules,i.e.5 properties in module 1 and 5 properties in module2 and so on, which implies redundancy of code.

Thus as a best practice we must have one properites file for a struts app whereas the struts-config.xml may be multiple.

I accept my limited knowledge of the subject. I need to confirm urgently, that is why I am being a little careful.

Thanks in advance once again.
Regards,
Roshani
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

thanks for the clarifications ... even i was stuck at a minute point ... which i now understand after reading this ... :-) thanks


http://plainoldjavaobject.blogspot.in
 
 
subject: Multiple properties files