在 Struts 2 中绑定后更改参数 [英] Changing parameters after bind in Struts 2

查看:28
本文介绍了在 Struts 2 中绑定后更改参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从用户那里接收一些参数的操作(例如日期).此操作会生成许多不同的报告,因此它有许多不同的方法.我需要在每个方法之前调整这些参数(将时间设置为午夜).prepare 方法在绑定参数之前执行.是否有任何其他拦截器或任何其他约定允许我这样做?

解决方案

使用

<块引用>

<!-- params-prepare-params 技巧的一个例子.这个栈与 defaultStack 完全相同,除了它在准备拦截器之前包括一个额外的拦截器:参数拦截器.当您希望直接应用参数时,这很有用到您希望从外部加载的对象(例如 DAO或数据库或服务层),但无法加载该对象直到至少加载了 ID 参数.通过加载参数两次,你可以检索对象prepare() 方法,允许第二个参数拦截器将值应用于对象.-->

如果您正在使用 Convention Plugin 将其应用于操作

@Action(value="action1",interceptorRefs=@InterceptorRef("paramsPrepareParamsStack"))

I have an action that receives some parameters from user (e.g. date). This action produces many different reports, so it has many different methods. I need to tune those parameters (set a time to midnight) before every method. The prepare method is executed before parameters are bound. Is there any other interceptor or any other convention that allows me to do that?

解决方案

Use the <interceptor-ref name="paramsPrepareParamsStack"/>

<!-- An example of the params-prepare-params trick. This stack
    is exactly the same as the defaultStack, except that it
    includes one extra interceptor before the prepare interceptor:
    the params interceptor.

    This is useful for when you wish to apply parameters directly
     to an object that you wish to load externally (such as a DAO
     or database or service layer), but can't load that object
     until at least the ID parameter has been loaded. By loading
     the parameters twice, you can retrieve the object in the
     prepare() method, allowing the second params interceptor to
     apply the values on the object. -->

If you are using the Convention Plugin apply it on action

@Action(value="action1", interceptorRefs=@InterceptorRef("paramsPrepareParamsStack"))

这篇关于在 Struts 2 中绑定后更改参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆