【问题标题】:Store Interceptor and loose Value stack when redirection重定向时存储拦截器和松散值堆栈
【发布时间】:2012-10-07 23:58:35
【问题描述】:

我有 2 个动作。第一个显示表格,另一个处理表格。如果 processAdd 操作未验证,则将 redirectAction 返回到 Add 操作。 Store 拦截器在“添加”操作中显示正确的错误,但在重定向操作期间表单上填写的值会丢失。

我在重定向时loose Value Stack,我明白这一点。

有什么解决办法吗?

不想使用结果参数,工作量太大。

 <action name="add" class="com.myapp.actions.StudentAction" method="input">
            <interceptor-ref name="store">
                <param name="operationMode">RETRIEVE</param>
            </interceptor-ref>
            <result name="input" type="tiles">/student.edit.tiles</result>
        </action>

        <action name="processAdd" class="com.myapp.actions.StudentAction">
            <interceptor-ref name="store">
                <param name="operationMode">STORE</param>
            </interceptor-ref>
            <interceptor-ref name="defaultStack" />
            <result name="success" type="redirectAction">list</result>
            <result name="input" type="redirectAction">add</result>
            <result name="failure" type="redirectAction">add</result>
        </action>

【问题讨论】:

  • @quaternion,我试过但没有成功。你能用我上面的代码解释一下你想让我怎么做吗?
  • 查看文档,它解释说您可以指定 struts2 常量来实现这一点,我认为自定义拦截器堆栈中的显式包含参数也会使其工作:struts.apache.org/2.2.3/xwork-core/apidocs/com/opensymphony/…
  • 我不知道为什么要在消息失败时重定向到另一个操作?以及为什么要针对验证失败做一些工作。
  • @umesh-awasthi,我有自己的理由这样做。抱歉,添麻烦了。我可以用会话等来做到这一点,但想知道框架内的任何自动支持。范围拦截器就是答案。

标签: jakarta-ee struts2


【解决方案1】:

您要查找的是 Scope Interceptor,而不是 Store Interceptor。

【讨论】:

  • 谢谢。这就是我一直在寻找的。​​span>
【解决方案2】:

MessageStoreInterceptor

用于存储 ValidationAware 操作的消息/错误的拦截器 并将错误输入到 HTTP 会话中,以便可以检索 在稍后阶段。这允许操作的消息/错误和字段 错误的可用时间比特定 HTTP 请求的可用时间更长。

您无法使用消息存储拦截器获取值堆栈数据,它关心的是操作消息/错误和字段错误。

或者,您可以使用 链拦截器 或在会话中存储值,即使消息存储拦截器使用会话对象来存储消息/错误。

【讨论】:

  • 谢谢。已经知道了。不想将错误从一个动作存储到另一个动作。我对属性值感兴趣。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-21
  • 1970-01-01
  • 2015-08-22
  • 2013-03-11
  • 2017-11-28
相关资源
最近更新 更多