• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Struts 1: Access MessageResources from doStartTag in TagSupport

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic