This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
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"/>
2) For the <bean:write> do i have to write as: <bean:message key="SearchAddress.search.button.label" bundle="alternate" />
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
Joined: Feb 15, 2005
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.
Joined: May 15, 2006
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.