XWork2 Action serves as to capture a particular execution logic. It is distinguished by its unique name and namespace combination.

XWork2 parses its xml configuration according to order. If an action extends off another parent action, the parent action MUST be defined before the action that planned to extend it

Name and namespace

An action is identified by its name and namespace combination. By default, if an action with a specified name and namespace does not exists, it will fall back to an action with the same name but a default namespace (empty namespace) if such a combination exists.

<xwork>
  <package name="default" namespace="/myNamespace">
     ...
     <action name="myAction" ...>
       ....
     </action>
     ...
  </package>
</xwork>

Action class

An action class could be :-

  • plain pojo (extends java.lang.Object which by default every java class does)
  • implements com.opensymphony.xwork2.Action interface
  • extends com.opensymphony.xwork2.ActionSupport

Action Context

Action could access its context using ActionContext. Parmameter passing could be done using this action context. Following is an example

ActionProxyFactory factory = ActionProxyFactory.getFactory();
 factory.createActionProxy(configuration, "actionAlias", "/namespace", 
   new LinkedHashMap() {
      {
         // pass in parameter 
         put("someParameter", "some parameter value");
      }
   }
 );

 // latter on, we could do this

 ActionContext context = ActionContext.getContext();
 Map contextMap = context.getContextMap();
 contextMap.get("someParameter");