The action mappings are the basic "unit-of-work" in the framework. Essentially, the action maps an identifier to a handler class. When a request matches the action's name, the framework uses the mapping to determine how to process the request.
Action Mappings
The action mapping can specify an interceptor stack, a set of result types, and a set of exception handlers. But, only the name
attribute is required. (Everything else can also be provided at a global scope.)
Code Block | ||
---|---|---|
| ||
<action name="Hello" class="cookbook2.Hello"> <result>/pages/Hello/Result.jsp</result> <result name="input">/pages/Hello/Input.jsp</result> </action> |
Action Names
In a web application, the name
attribute is matched a part of the location requested by a browser (or other HTTP client). The framework will drop the host and application name and the extension, and match what's in the middle. So, a request for http://www.planetstruts.org/action2-cookbook/Home.do
will map to the Home
action.
...
Code Block | ||
---|---|---|
| ||
<saf:form action="Hello" method="POST"> <saf:textfield label="Please enter your name" name="name"/> <saf:submit/> </saf:form> |
Action Aliases
The default entry method to the handler class is defined by the Action interface.
...
If there is no
execute
method and no method specified in the configuration, the framework will throw an exception.
Bang Aliases
The Action method to execute can also be embedded in the form or tag reference. In either tag or form reference, use an exclamation mark (or "bang") to specify both the action name and method.
...
The idiom "Register!input
" will invoke the input
method on the Action class mapped to the Register
action.
Making Do
However, the method is named or selected, the method must be public, take no arguments, and return a String. The String indicates the name of the result to execute.
...
The
do
prefix makes it possible to use alias names that might otherwise be invalid method names.
ActionSupport Default
If the class attribute in an action mapping is left blank, the com.opensymphony.xwork.ActionSupport
class is used as a default.
...
The ActionSupport class has
execute
and input
methods that return "success".
Post-Back Default
A good practice is to link to actions rather than pages. An effect of this strategy is that an action will fire before a page renders. Another common stategy is to first render a page using an alias, and then have it submit back to the default execute method. Using these strategies together creates an opportunity to use a "post-back" form that doesn't specify an action. The form simply submits back to the action that created it.
...
If validation passes, control will pass to the Result.jsp
; otherwise, control passes back to Input.jsp
.
Action Default
Usually, if an action is requested, and the framework can't map the request to an action name, the result will be the usual "404 - Page not found" error. But, if you would prefer that an ominbus action handle any unmatched requests, you can specify a default action. If no other action matches, the default action is used instead.
...