Struts2 JPA Validation error how to forward to action and not lose ActionErrors messages?

孤者浪人 提交于 2019-12-23 05:49:36

问题


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 &lt;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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!