advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Adding Spice to Struts Part 2 :

Multiple Message Resources in Struts…

In one way, Struts does support multiple resource bundles. to many of us though, the default Struts mechanism of using multiple resource bundles is not sufficient. Here is a brief introduction to the default Struts mechanism for using multiple resource bundles.

  • You can define multiple message resource file configurations in the struts-config.xml in the following way:
<message-resources key="first" parameter="a.properties"/>

<message-resources key="second" parameter="b.properties"/>
  • In order to use multiple resources from defined bundle, within the JSP you have to qualify the <bean:message> tag with the name of the bundle. For example, if you want to access a resource from the b.properties bundle, then the JSP will look like this:
<bean:message bundle="second" key="some.message.key"/>

Here, you are pointing to the right resource bundle by mapping against the specified "key" in the configuration file.

This method presents the following problems:

  • Moving resources between different resource bundle means you have to change the JSPs to point to the right resource bundle.
  • This approach needs to be decided before you advance in your development, as revisiting all the JSPs to conform to this style of using multiple resource bundles can be impossible for a large scale and distributed projects.
  • If you are using Commons Validator with Struts, it is reported that Validator framework does not work with multiple resource bundle files.

The solution is then to define as many resource files as you like and to consolidate them before the Struts initializes and caches them in a local memory storage. Again, it comes out that the right point to do that is the initialization time and it is evident that we have to override the Struts ActionServlet class in order to do what we want to do.

By analyzing, how Struts stores and retrieves the values against a particular resource bundle key, we discovered the following:

  • Struts uses a class called MessageResources which is responsible for loading any specified resource bundle file and parsing through it before returning the value for a given message key.
  • When you specify multiple resource files the way we explained before, the Struts loads all the resource files but stores them under different keys. That is why you need to specify the key in the JSP when we attempt to retrieve the value for a message key.

What we really need to do is to parse all the specified resource files at one go and store all the resources under one global key. In order to do that, we decided to come up with our own CustomMessageResources class (Listing 2), which will accept a list of message resource files, parse all of them and store them in an internal cache. When a message key is passed onto it, it will look for the value in the internal cache store and return the appropriate value stored against the specified key.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 BlackBerry Application Development Resources
 Microsoft Visual Studio 2010 Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow
Facebook Makes Major PHP Push With HipHop
Free Ride Over for Microsoft Azure Users
Drupal Opens the Garden to Boost CMS
Oracle Talks Plans for Linux, Solaris
Azure Makes Cloud Computing Innovation Safe
Red Hat's JBoss Looks Ahead
Microsoft Readies Two Windows Phone Systems?

Apple Surveying iPhone Developers? Happiness With The App Store
HTML 5 Leaves Client Storage Open to Web Attacks
Basic Market Forecasting with Encog Neural Networks
Location-Aware App Review
The Future of Web Content -- HTML5, Flash, and Mobile Apps
Moonlight 3.0 Preview Offered For Rich Internet Apps on Linux and Unix
Why a Moderator is Key in the Engineering Review Process, Part II
Windows 7 Features Your Clients Will Need on Day One
What Your Clients Will Ask About Windows 7
Melissa Data Helps Developers Improve the Quality of Business Data

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers