Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Reading the message resources from a form class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Accessing the message resources is simple from a JSP using the supplied tags, and accessing them is just as simple from an action class by calling getResources(). However, I need to access the message resources from a form class in one of my validation methods.

One of the ActionMessage constructors takes two parameters, a string (key into the message resources for the error message), and an Object used to fill in the first parameter of the message {0}.

My problem is that the value I want to send in as the second parameter to the ActionMessage constructor is something that I want to read from the action messages.

So far, I have not found an easy way to access these resources other than setting up a resource bundle in the form, which I don't like. Is there a way to get to the MessageResources from a form class?

Thanks.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The resource bundle is stored in Application scope. Fortunately, the ActionForm class that you are extending has a getServlet() method that will allow you to get a reference to the servlet that created the form bean, and hence to the servletContext object. You can therefore get the resource bundle with the following code:

MessageResources messageResources = (MessageResources)super.getServlet().getServletContext().getAttribute(Globals.MESSAGES_KEY));
[ January 30, 2006: Message edited by: Merrill Higginson ]
 
Jack Summers
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merrill,

That worked perfectly. Thank you so much!
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic