Struts2 JPA 验证错误如何转发到操作而不丢失 ActionErrors 消息?

发布于 2024-10-21 16:08:38 字数 889 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

拒绝两难 2024-10-28 16:08:38

检查这个可能会对您有所帮助,因为redirectAction意味着从头开始的新请求

链接

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

Link

昵称有卵用 2024-10-28 16:08:38

动作链可能就是您正在寻找的。

链接“允许操作将请求转发到目标操作,同时传播源操作的状态。”

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

娇女薄笑 2024-10-28 16:08:38

我找到了解决方案。我必须使用 <input type="redirectAction">youraction ..

并需要将其放入您的 SAVEAction

<interceptor-ref name="store">
    <param name="operationMode">STORE</param>
</interceptor-ref>
  

,最后放入您的 displayAction 中(这将显示错误消息)

<interceptor-ref name="store">
    <param name="operationMode">AUTOMATIC</param>
</interceptor-ref>

或恢复

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文