You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Description

<action name="formTest" class="com.opensymphony.webwork.example.FormAction" method="processForm">

 

Actions are the basic "unit-of-work" in WebWork, they define, well, actions. An action will usually be a request, (and usually a button click, or form submit). The main action element (tag is too synonymous with JSP) has two parts, the friendly name (referenced in the URL, i.e. saveForm.action) and the corresponding "handler" class.

The optional "method" parameter tells WebWork which method to call based upon this action. If you leave the method parameter blank, WebWork will call the method execute() by default. If there is no execute() method and no method specified in the xml file, WebWork will throw an exception.

Also, you can tell WebWork to invoke "doSomething" method in your action by using the pattern "actionName!something" in your form. For example, "formTest!save.action" will invoke the method "save" in FormAction class. The method must be public and take no arguments:

public String save() throws Exception
  {
      ...
      return SUCCESS;
  }

 

All the configuration for "actionName" will be used for "actionName!something" (interceptors, result types, etc...)

Default Action

Since Webwork 2.2.1 you are also able to specify a default action to be executed when no other action is matched in the xwork.xml. This feature is provided mainly to eliminate the need to create an action class and/or element for very simple or similar results.  The default action name can be set inside the package element like below:

<default-action-ref name="simpleViewResultAction">

 

Caution

This feature should be configured such that there is only one default action per namespace. Therefore if you have multiple packages declaring a default action with the same namespace, it is not guaranteed which action will be the default.

 

Most of the content here provided by Matt Dowell <matt.dowell@notiva.com>

  • No labels