Struts 2 ModelDriven Action how to exclude some pr

2019-06-05 01:22发布

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
}

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!

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.

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

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.

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?

1条回答
姐就是有狂的资本
2楼-- · 2019-06-05 02:05

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>

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.

查看更多
登录 后发表回答