Struts2 JPA 验证错误如何转发到操作而不丢失 ActionErrors 消息?
我正在使用 Hibernate validator 4.1 来验证我的实体。
我有一个可以通过 viewDashboard
操作访问的仪表板。在我的操作类中,我设置了两个 List
的值,如下所示。
public String execute() throws Exception { listDocteur = service.listDocteur(); listUser = service.listUser(); return SUCCESS; }
在仪表板中,我有一个可以添加用户的提交按钮。
<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>
如果我提交无效值,我会看到错误消息,但我会丢失 2 个列表。如果我有 type="redirectAction"
,我会丢失错误消息。
在 Struts 1 中,我将转发到操作 viewDashboard.do
而无需重定向
,这样就可以了。我如何在 Struts2 中实现这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查这个可能会对您有所帮助,因为redirectAction意味着从头开始的新请求
链接
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.”
我找到了解决方案。我必须使用
<input type="redirectAction">youraction ..
并需要将其放入您的
SAVEAction
中,最后放入您的 displayAction 中(这将显示错误消息)
或恢复
I Found a solution. I have to use
<input type="redirectAction">youraction ..
and need to put this in your
SAVEAction
and finally, in your displayAction (that will display the error messages)
or RESTORE