Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Static parameters could be defined into an action through xwork.xml like bellow:(or pre-defined) parameters can be set to a Map property or to individual JavaBean properties.

  • Define the parameters to be set by adding the name(s) and value(s) to the action mapping element (in the application's struts.xml.
Code Block
  <action name="myAction" class=" ... MyAction">
     <param name="myStaticParam1">myStaticValue1</param>
     <param name="myStaticParam2">myStaticValue2</param>
     <param name="myStaticParam3">myStaticValue3</param>
  </action>

...

  • Ensure that staticParams Interceptor is included in the Action's stack.
    • (info) The default stack already includes staticParams.
  • Edit the Action so that it implements the Parameterizable interface.

Map property

  • Ensure the Action defines a setParams(Map) method.

...

  • The staticParams Interceptor will set the defined values to the Map, using the name as the entry key.

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:

JavaBean properties

  • Ensure that the Action defines JavaBean properties corresponding to the param elements in the action mapping.
  • The staticParams Interceptor will set the defined values to each JavaBean property that corresponds to a param element.
Code Block

Code Block

  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.

...

@see com.opensymphony.xwork.interceptor.StaticParametersInterceptor
@see com.opensymphony.xwork.config.entities.Parameterizable