You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniil Petrov <pe...@gmail.com> on 2009/09/17 16:14:34 UTC
Redirect from input result to action
Hi,
I have a view page, which displays an issue from the database. The results
are based on specified id in parameters. On the same page there is a form to
add some additional information to the issue. Validation (via validate()
method) is configured for the form, and in case of error I want to display a
page with details of the original issue and error description. I found
information about redirecting error messages via MessageStoreInterceptor.
The problem is that after redirect to view.action?issueId=${issueId},
${issueId} is being lost and the original page does not display anything.
Could someone give some hints how to make it work?
Here is a part from my struts.xml file:
<action name="view" method="view"
class="com.sample.pages.IssueAction">
<result name="success">/issue.jsp</result>
<result name="input">/issue.jsp</result>
</action>
<action name="save" method="save"
class="com.sample.pages.IssueAction">
<result name="input" type="redirect">
view.action?issueId=${issueId}
</result>
<result name="success" type="redirect">
view.action?issueId=${issueId}
</result>
</action>
Daniil
Re: Redirect from input result to action
Posted by Greg Lindholm <gr...@gmail.com>.
If you want to redirect to an action and pass parameters then define your
result like this (Seems like I just answered this question a day ago [1]):
<result type="redirectAction">
<param name="actionName">view</param>
<param name="issueId">${issueId}</param>
</result>
If you want to preserve all messages across redirects take a look here [2],
it's a lot easier to use then MessageStoreInterceptor.
With that said, it's almost never the right answer to do a redirect on a
result of "input" since input is for validation errors and the stuff that is
causing the validation error will not (normally) survive the redirect. So a
user enters some bad data, validation detects this and returns a result of
"input" then the redirect will lose the data (all data, bad and good) the
user entered.
[1]
http://www.nabble.com/problem-with-encoding-of-parameters%2C-type%3D%22redirect%22-ts25456381.html
[2]
http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/
On Thu, Sep 17, 2009 at 10:14 AM, Daniil Petrov <pe...@gmail.com> wrote:
> Hi,
>
> I have a view page, which displays an issue from the database. The results
> are based on specified id in parameters. On the same page there is a form
> to
> add some additional information to the issue. Validation (via validate()
> method) is configured for the form, and in case of error I want to display
> a
> page with details of the original issue and error description. I found
> information about redirecting error messages via MessageStoreInterceptor.
> The problem is that after redirect to view.action?issueId=${issueId},
> ${issueId} is being lost and the original page does not display anything.
> Could someone give some hints how to make it work?
>
> Here is a part from my struts.xml file:
>
> <action name="view" method="view"
> class="com.sample.pages.IssueAction">
> <result name="success">/issue.jsp</result>
> <result name="input">/issue.jsp</result>
> </action>
> <action name="save" method="save"
> class="com.sample.pages.IssueAction">
> <result name="input" type="redirect">
> view.action?issueId=${issueId}
> </result>
> <result name="success" type="redirect">
> view.action?issueId=${issueId}
> </result>
> </action>
>
> Daniil
>