• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pagecontext object in Action class

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this following code I need Object of type PageContext in the following code to pass in the RequestUtil.message(), is there any way to get the pagecontext object,

public class MyAction extends Action
{
public ActionForward doExecute(ActionMapping mapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {
//initilization code here

mstrName = RequestUtils.message(pageContextobj, resourceKey, null, "PrpName");

}

}
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The PageContext object is for use only within a JSP, so you can't get it in an Action class. However, the Action class that your Action extends has some methods that will accomplish the same thing as the RequestUtils.message() method does.

use this code instead:

mstrName = getResources(request).getMessage("PrpName");
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Merrill Higginson:
However, the Action class that your Action extends has some methods that will accomplish the same thing as the RequestUtils.message() method does.

use this code instead:

mstrName = getResources(request).getMessage("PrpName");



this is returning the ???en_US.firstname??? instead of Firt Name
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried the above code snippet again, and it retrieves the contents of the message for me. Are you 100% sure the message key PrpName exists in the ApplicationResources.properties file?

This code gets the message using the default locale. If you want to get the message using the locale of the current user, use this code:

String mstrName = getResources(request).getMessage(getLocale(request), "PrpName");

Both of the aboe code snippets retrieved the contents of the message when I tried them for a message key I know exists in my ApplicationResources.properties file.
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Merrill

Originally posted by Merrill Higginson:

String mstrName = getResources(request).getMessage(getLocale(request), "PrpName");

Both of the aboe code snippets retrieved the contents of the message when I tried them for a message key I know exists in my ApplicationResources.properties file.



I think my resource bundle file is not loading
but when i use the Tag lib using the following call I can get the resource bundle file.
pageContext.setAttribute(resourceKey, resourceBundle, PageContext.APPLICATION_SCOPE);


Is there any way to set the resourcekey and bundlefile name so that I can get these two things in my action class.


I am thining If I can set the request.setAttribute()

Please comment!!!11
[ May 01, 2006: Message edited by: Santosh Maskar ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm scratching my head as to why this doesn't work for you. Here's one more thing to try. The getResources method has another overloaded version that takes the HttpServletRequest object and a string indicating which resource bundle to use as parameters. Try this:

msg = getResources(request, "en_US").getMessage("key");
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic