This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts 1: Access MessageResources from doStartTag in TagSupport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1: Access MessageResources from doStartTag in TagSupport" Watch "Struts 1: Access MessageResources from doStartTag in TagSupport" New topic
Author

Struts 1: Access MessageResources from doStartTag in TagSupport

Adam Stokar
Greenhorn

Joined: Sep 01, 2010
Posts: 2
I am trying to pull in my Struts (1.3) ApplicationResources.properties file (based on the locale of the request) inside the doStartTag method of a Java Tag. I am using the following code :

HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
MessageResources resources = (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);

System.out.println(resources.getMessage(request.getLocale(),"global.state.label");

However, it is throwing a NullPointerException (resources is NULL).

Is there a better way to do this? This is the same code used in the Action.getResources(request) method but it doesn't seem to be working in the context of the tag.
Adam Stokar
Greenhorn

Joined: Sep 01, 2010
Posts: 2
I figured it out, here's the solution in case anyone else needs it:

HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
MessageResources messages = MessageResources.getMessageResources("com.mycompany.struts.ApplicationResources");
messages.getMessage(request.getLocale(),"global.choose.label");

The string passed into the getMessageResources(String) method should be the parameter attribute of the <message-resources> tag in your struts-config.xml.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 1: Access MessageResources from doStartTag in TagSupport
 
Similar Threads
Getting MessageResources inside ActionForm
Specifying a message resource file within the Action class
Struts Message resources
accessing message resources in processPreprocess
Getting values from properties in validate-using multiple message-resources in struts