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.

 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 34
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%.

IBM Brings Developers Into the Cloud
Apache at 10: You Can't Buy Us
Microsoft's CodePlex Foundation Moving Forward
Apple Claims 100,000 Apps, Google Analyzes Them
Nokia Latest to Play Opera Mobile 10 Browser
PayPal Opens Up Payment Platform to Devs
Ubuntu Linux 9.10 'Karmic Koala' Starts Its Climb
IBM Links Rational Developer Tools, Tivoli Apps
Libraries Give Vista Apps a Windows 7 Look
Ubuntu: The 'Default Alternative' to Windows?

Delivering Web-based Embedded Fonts in CSS 3
Adobe Helps PHP Developers Create Rich Internet Applications
Java Developers Finding a Home at Adobe Flex
Virtualization Delivers a Dynamic Infrastructure
Consuming XML Web Services in iPhone Applications
Build a More Agile Business with IBM
POJO-Based Solutions for LDAP Access: One Good, One Better
IBM Offers Enhanced Measurement and Management for Energy Usage
IBM Helps Transformation to an Information-Based Enterprise
Top Five Touch UI-Related Design Guidelines

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