Multiple message resource property file in Struts

      

Recently I came up with a requirement where in we have to display messages from multiple bundle resource (message resource) property files in Struts using <bean:message>.
Following are the steps for the same:

  1. Make an entry of message resource file name in struts-config.xml file.
    <message-resources
    	parameter="net.viralpatel.struts.MessageResource"
    	key="myResource"></message-resources>
    
    <message-resources
    	parameter="net.viralpatel.struts.NewMessageResource"
    	key="myOtherResource"></message-resources>
    
  2. Once this is done, the message resource file can be accessed by using the key (in this case we have myResource & myOtherResource). The key should be used in <bean:message> tag in jsp to display perticular message from the resource property file. bundle=”" attribute of <bean:message> is used to identify the perticular property file.
    <bean:message bundle="myResource"
    		key="somekey.in.myresource" />
    <bean:message bundle="myOtherResource"
    		key="somekey.in.myotherresource"/>
    

Facebook  Twitter      Stumbleupon  Delicious
  

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

Copyright © 2010 ViralPatel.net. All rights reserved.