JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > FAQ > How do I get static parameters into my action
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  How do I get static parameters into my action
Added by scud, last edited by scud on Mar 30, 2006  (view change)
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 running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators