Dashboard > WebWork > ... > FAQ > How do I get static parameters into my action
  WebWork Log In View a printable version of the current page.  
  How do I get static parameters into my action
Added by tm_jee, last edited by tm_jee on Nov 20, 2005
Labels: 
(None)

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

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators