Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use multiple message resources in Struts 2

 
Peter Lo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic