You can preserve errors and messages from one action to another, across
a redirect, with the MessageStoreInterceptor. See here:
http://struts.apache.org/2.x/docs/message-store-interceptor.html
This lets you avoid chaining which, of course, is usually evil. :-)
- Gary
jjgould wrote:
Ted, et. al.,
I am also interested in accessing the previous action from the target action
of a "chain" result. But, the reason I want to get to that action is not
because of any bean properties, but because I need the action errors, action
messages, and field errors that may have been placed there by my validation.
In my case, action "one" is used to view an object that is an aggregate of a
lot of smaller objects. Action "two" is used to add a new component object
to the collection. However, when there is a validation error on the new
object, the application needs to forward back to action "one" to redisplay
the object and it needs to have the field error messages. The struts.xml
looks like this:
<action
name="*/view"
class="com.sherwin.sd.eris.web.action.CaseAction"
method="execute">
{1}
<result name="success">/WEB-INF/jsp/case/viewCase.jsp</result>
</action>
<action
name="*/issue/add"
class="com.sherwin.sd.eris.web.action.IssueAction"
method="addIssue">
{1}
<result
name="input"
type="chain">
{1}/view
</result>
<result
name="success"
type="redirect-action">
{1}/view
</result>
</action>
Any tips you can offer are greatly appreciated.
- Jack Gould
Sherwin-Williams
Cleveland, Ohio, USA
Ted Husted wrote:
Binding two Action classes together that way sounds like a "slippery
slope" to me. It seems like a better practice to rely on standard
JavaBean semantics, and access the values that need to be brought
forward through the usual get and set methods.
One other thing to try, which you may have started to do, would be to
save the object as a request attribute, as an alternative to the chain
result. In this case, both Actions would have setRequest and
getRequest methods.
ActionOne
getRequest().put("searchParameter",getSearchParameter());
ActionTwo
setSearchParameter( (SearchParameter) getRequest().get("searchParameter")
);
The JVM is optimized for property methods, and overall it's a better
practice to go through the getters and setters than access fields
directly.
-- HTH, Ted
<http://www.husted.com/ted/blog/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]