Static parameters could be defined into an action through xwork.xml like bellow:
<action name="myAction" class=" ... "> <param name="myStaticParam1">myStaticValue1</param> <param name="myStaticParam2">myStaticValue2</param> <param name="myStaticParam3">myStaticValue3</param> </action>
+ Method A +
Have the action class itself implements com.opensymphony.xwork.config.entities.Parameterizable and the static parameters will be set into it through the setParams(Map) method. In the example above, the key and value will be as tabulated below:
key |
value |
---|---|
myStaticParam1 |
myStaticValue1 |
myStaticParam2 |
myStaticValue2 |
myStaticParam3 |
myStaticValue3 |
+ Method B +
Have the action class itself define getter/setter for the static parameter itself and those static parameter will be set through those setter and getter. In the case above, the action class could be as follows:
public class MyAction extends ActionSupport { ... public String getMyStaticParam1() { ....} public void setMyStaticParam1(String myStaticParam1) { ... } public String getMyStaticParam2() { ... } public void setMyStaticParam2(String myStaticParam2) { ... } public String getMyStaticParam3() { ... } public void setMyStaticParam3(String myStaticParam3) { ... } ... }
The getter and setter, will be set appropriately.
NOTE: For this to work, 'static-params' interceptor must be added to the action.
@see com.opensymphony.xwork.interceptor.StaticParametersInterceptor
@see com.opensymphony.xwork.config.entities.Parameterizable