问题
I'm using Hibernate validator 4.1 to validate my Entity.
I have a dashboard that I can access from the action viewDashboard
. In my action class, I set the values of two List
like this.
public String execute() throws Exception { listDocteur = service.listDocteur(); listUser = service.listUser(); return SUCCESS; }
In the DashBoard, I have a submit button that can add a User.
<action name="saveUser" class="com.test.action.CreateUserAction" method="execute"> <interceptor-ref name="mybasicStackWithValidation" > </interceptor-ref> <result name="input">/WEB-INF/jsp/viewDashboard.jsp</result> <result name="success" type="redirectAction">viewDashboard</result> </action>
If I submit an invalid value, I'll see the error messages, but I'll lose my 2 Lists. If I have a type="redirectAction"
, I lose the error messages.
In Struts 1, I would forward to the action viewDashboard.do
without a redirect
and that will works. How can i achieve this in Struts2?
回答1:
Check this may be it will help you, since redirectAction means a new request at from beginning
Link
回答2:
Action Chaining may be what you are looking for.
Chaining “allows an Action to forward requests to a target Action, while propagating the state of the source Action.”
回答3:
I Found a solution. I have to use <input type="redirectAction">youraction ..
and need to put this in your SAVEAction
<interceptor-ref name="store"> <param name="operationMode">STORE</param> </interceptor-ref>
and finally, in your displayAction (that will display the error messages)
<interceptor-ref name="store"> <param name="operationMode">AUTOMATIC</param> </interceptor-ref>
or RESTORE
来源:https://stackoverflow.com/questions/5287160/struts2-jpa-validation-error-how-to-forward-to-action-and-not-lose-actionerrors