Struts 2 ModelDriven Action如何从beaing更新中排除某些属性 [英] Struts 2 ModelDriven Action how to exclude some properties from beaing updated
问题描述
我们正在使用 ModelDriven
界面的操作。该操作具有 scopedModelDriven
拦截器,我们将模型保存在会话中。模型如下:
We are using an action with ModelDriven
interface. The action has the scopedModelDriven
interceptor and we save the model in session. The model is as below:
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
字段,映射到 Fundtransfer
bean自动通过 modelDriven
拦截器。
听到之前,每件事都是正常的!
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通常用于通过getters / 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如何从beaing更新中排除某些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!