You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Vincent Craven <pa...@cravenfamily.com> on 2003/06/17 18:13:49 UTC

Getting MessageResources from Action

I need to break some with the MVC model, and
output information from within my Action.

Specifically, I have a long running process that I
give status updates to the user by putting info on
the output stream and then flushing it.

My problems is that I want the messages displayed
to the user to come from the application resources
file. I've tried the code below, but getPageContext
returns a null. I assume because I'm not really in
a jsp/page. But I don't know another good way to get
a message resources object. Can anyone offer advice?

JspFactory factory = JspFactory.getDefaultFactory();

PageContext pageContext = factory.getPageContext(
	MyServlet.getInstance(),
	request,
	response,
	null,  // errorPageURL
	false, // needsSession
	JspWriter.DEFAULT_BUFFER,
	true   // autoFlush
	);

messages = (MessageResources) pageContext.getAttribute(Action.MESSAGES_KEY,
			   PageContext.APPLICATION_SCOPE);
out.print( messages.getMessage(defaultLocale,"errors.mymessage",
myparametervalue) );
out.flush();

Paul Vincent Craven
paul@cravenfamily.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org