如何从Struts 2中排除ModelDriven Action的某些属性以使其不被更新 [英] How to exclude some properties of ModelDriven Action from being updated in Struts 2

查看:49
本文介绍了如何从Struts 2中排除ModelDriven Action的某些属性以使其不被更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用带有 ModelDriven 界面的动作.该操作具有 scopedModelDriven 拦截器,我们将模型保存在会话中.

We are using an action with ModelDriven interface. The action has the scopedModelDriven interceptor and we save the model in session.

模型如下:

public class Fundtransfer{

private String amount;
private String sourceAccount;
private String destinationAccount;
private String sign

//setter's and getter's ommited
}

Fundtransfer bean被用作模型.JSP表单具有数量, sourceAcount destinationAcount 字段,这些字段通过 modelDriven 拦截器自动映射到 Fundtransfer bean.一切正常,直到听到!

The Fundtransfer bean is used as a model. The JSP form has amount, sourceAcount and destinationAcount fields which maps to Fundtransfer bean automatically via modelDriven interceptor. Every thing is normal till hear!

当然,用户可以简单地修改HTML表单,并将名为 sign 的变量传递给操作,然后拦截器将为它更新Bean.

Of course the user can simple tramped the HTML form and pass a variable named sign to the action and the interceptor will update it the bean.

是否有可能我们可以在无法通过 ModelDriven 拦截器更新符号值的情况下配置模型.

Is it possible that we can configure a model in away that the sign value could not be updated via ModelDriven interceptor.

我知道我可以创建一个新bean,然后将其复制到 Fundtransfer bean或使用某种继承.有更好的方法吗?

I know I can create a new bean and then copy it to Fundtransfer bean or use some sort of inheritance. Are there better ways.

我们正在使用的真正的bean很大,并且其中有一些嵌套的bean.

The real bean which we are using is huge and also some of the has nested beans.

我想也许我可以使用一些方面的技巧,但我不知道是否可能?

I thought may be I can use some aspect tricks but I don't know is it possible or not?

推荐答案

ModelDriven bean通常用于通过getter/setter进行读取/写入.您可以在此处控制访问.但是,如果您还不知道Struts2通过 params 拦截器,它使用OGNL填充模型.您可以通过参数 excludeParams 例如

The ModelDriven bean usually used for read/write via the getters/setters. You can control access here. However, if you don't know yet Struts2 set parameters via params interceptor which uses OGNL to populate the model. You can control this interceptor via parameters excludeParams for example

<interceptor-ref name="params">
  <param name="excludeParams">
    dojo\..*,^struts\..*,sign
  </param>
</interceptor-ref>

另一种方法是使用 ParameterNameAware ,您可以在其中实现参数的黑/白列表.请注意,这种方法可能会通过第一种方法打开受限参数的大门.

Another approach is to use ParameterNameAware where you could implement black/white list of parameters. Be careful with this approach can open door to restricted parameters by the first method.

这篇关于如何从Struts 2中排除ModelDriven Action的某些属性以使其不被更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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