开发者

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

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?


Check this may be it will help you, since redirectAction means a new request at from beginning

Link


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.”


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜