Struts2 JPA 验证错误如何转发到操作而不丢失 ActionErrors 消息? [英] Struts2 JPA Validation error how to forward to action and not lose ActionErrors messages?
问题描述
我正在使用 Hibernate 验证器 4.1 来验证我的实体.
我有一个仪表板,我可以从操作 viewDashboard
访问它.在我的动作类中,我像这样设置了两个 List
的值.
在仪表板中,我有一个可以添加用户的提交按钮.
<前><action name="saveUser" class="com.test.action.CreateUserAction" method="execute"><interceptor-ref name="mybasicStackWithValidation" ><result name="input">/WEB-INF/jsp/viewDashboard.jsp</result><result name="success" type="redirectAction">viewDashboard</result>动作>如果我提交无效值,我会看到错误消息,但我会丢失我的 2 个列表.如果我有 type="redirectAction"
,我会丢失错误消息.
在 Struts 1 中,我会在没有 redirect
的情况下转发到操作 viewDashboard.do
并且这会起作用.我如何在 Struts2 中实现这一点?
我找到了解决方案.我必须使用 <input type="redirectAction">youraction ..
并且需要把它放在你的 SAVEAction
最后,在您的 displayAction(将显示错误消息)中
<前>或恢复
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?
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
这篇关于Struts2 JPA 验证错误如何转发到操作而不丢失 ActionErrors 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!