File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes how to use multiple message resources in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to use multiple message resources in Struts 2" Watch "how to use multiple message resources in Struts 2" New topic
Author

how to use multiple message resources in Struts 2

Peter Lo
Greenhorn

Joined: Jun 22, 2007
Posts: 4
Hello,

I've been working with Struts 1 before, and am currently trying to convert an existing project to Struts 2.

I currently have 2 problems.
1) We don't use the default application.properties, but instead a set of custom property files in a different directory. And in the past, we would reference them in the struts-config.xml, and use a bundle key to distinguish which bundle to use in what situations.

The key point was that, the bundle key was always used to select the desired bundle whether inside a java class, or within a JSP.

Right now, I'm not entirely sure how to duplicate this effort in Struts 2 as there doesn't seem to be a place to specify it in the Strut2's struts.xml. So my question is, how do I set up multiple non-default property files such that I can manually select them?

2) Where should I be storing these files? Since I can't reference them in the struts.xml, I'm guessing I have to just figure out how Struts2 searches for these things.

Any help on this topic would be most appreciated.

Peter
Peter Lo
Greenhorn

Joined: Jun 22, 2007
Posts: 4
Just to answer my own question, I don't think this is the best way to do this, as it feels very much like a hack solution. It just seems like Struts1 had a much more elegant solution when it allowed you to refer to bundles directly by bundle keys. But it's the best I could find:

within java classes:
--------------------
// some code
LocalizedTextUtil.clearDefaultResourceBundles();
if (//some condition to use resource bundle 1) {
LocalizedTextUtil.addDefaultResourceBundle(classNameOfResourceBundle1);
} else {
LocalizedTextUtil.addDefaultResourceBundle(classNameOfSomeOtherBundle);
}

within the JSP:
---------------
I enclosed the entire JSP page with this:
[s:i18n name="classNameOfResourceBundle1"]
[/s:i18n]
Peter Lo
Greenhorn

Joined: Jun 22, 2007
Posts: 4
Just to answer my own question, I don't think this is the best way to do this, as it feels very much like a hack solution. It just seems like Struts1 had a much more elegant solution when it allowed you to refer to bundles directly by bundle keys. But it's the best I could find:

within java classes:
--------------------
// some code
LocalizedTextUtil.clearDefaultResourceBundles();
if (//some condition to use resource bundle 1) {
LocalizedTextUtil.addDefaultResourceBundle(classNameOfResourceBundle1);
} else {
LocalizedTextUtil.addDefaultResourceBundle(classNameOfSomeOtherBundle);
}

within the JSP:
---------------
I enclosed the entire JSP page with this:
[s:i18n name="classNameOfResourceBundle1"]
[/s:i18n]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use multiple message resources in Struts 2