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.

XML error: undefined entity at line 19
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%.

Linux Vendors Head to the Cloud in Search of Cash
iPhone 3GS: Overheating Fears, OS Update Nears
PostgreSQL 8.4 Revs Up Database Admin, Security
PHP 5.3 Accelerates PHP
Sun Releases NetBeans 6.7 IDE for Java, PHP
Why Firefox Doesn't Take Google Chrome Features
First Major PHP Update in Years Coming Soon
Red Hat CEO Calls on Oracle to Keep Java Open
Google Widens AdSense for iPhone, Android Apps
Eclipse Galileo Releases 33 Open Source Projects

A Taste of JavaFX for the Uninitiated
A Guide to Caching and Compression for High Performance Web Applications
How User-Centered Design Can Put User Stories in Proper Context
Explore C# 4's New Dynamic Types and Named/Optional Parameters
Enterprise Architecture: The Journey Begins Here, Part 2
Create a Syslog Sender/Receiver Using the MS Winsock Control
AMD CodeAnalyst Helps Developers Optimize and Tune Applications
Securing Microsoft's Cloud Infrastructure
Introducing the Azure Services Platform
An Introduction to Microsoft .NET Services for Developers

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs