Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » dispatcher » mapper » [javadoc | source]
org.apache.struts2.dispatcher.mapper
public class: DefaultActionMapper [javadoc | source]
java.lang.Object
   org.apache.struts2.dispatcher.mapper.DefaultActionMapper

All Implemented Interfaces:
    ActionMapper

Direct Known Subclasses:
    Restful2ActionMapper, RestActionMapper

Default action mapper implementation, using the standard *.[ext] (where ext usually "action") pattern. The extension is looked up from the Struts configuration key struts.action.extension.

To help with dealing with buttons and other related requirements, this mapper (and other ActionMapper s, we hope) has the ability to name a button with some predefined prefix and have that button name alter the execution behaviour. The four prefixes are:

In addition to these four prefixes, this mapper also understands the action naming pattern of foo!bar in either the extension form (eg: foo!bar.action) or in the prefix form (eg: action:foo!bar). This syntax tells this mapper to map to the action named foo and the method bar.

Method Prefix

With method-prefix, instead of calling baz action's execute() method (by default if it isn't overriden in struts.xml to be something else), the baz action's anotherMethod() will be called. A very elegant way determine which button is clicked. Alternatively, one would have submit button set a particular value on the action when clicked, and the execute() method decides on what to do with the setted value depending on which button is clicked.

 <!-- START SNIPPET: method-example -->
 <s:form action="baz">
     <s:textfield label="Enter your name" name="person.name"/>
     <s:submit value="Create person"/>
     <s:submit name="method:anotherMethod" value="Cancel"/>
 </s:form>
 <!-- END SNIPPET: method-example -->

Action prefix

With action-prefix, instead of executing baz action's execute() method (by default if it isn't overriden in struts.xml to be something else), the anotherAction action's execute() method (assuming again if it isn't overriden with something else in struts.xml) will be executed.

 <!-- START SNIPPET: action-example -->
 <s:form action="baz">
     <s:textfield label="Enter your name" name="person.name"/>
     <s:submit value="Create person"/>
     <s:submit name="action:anotherAction" value="Cancel"/>
 </s:form>
 <!-- END SNIPPET: action-example -->

Redirect prefix

With redirect-prefix, instead of executing baz action's execute() method (by default it isn't overriden in struts.xml to be something else), it will get redirected to, in this case to www.google.com. Internally it uses ServletRedirectResult to do the task.

 <!-- START SNIPPET: redirect-example -->
 <s:form action="baz">
     <s:textfield label="Enter your name" name="person.name"/>
     <s:submit value="Create person"/>
     <s:submit name="redirect:www.google.com" value="Cancel"/>
 </s:form>
 <!-- END SNIPPET: redirect-example -->

Redirect-action prefix

With redirect-action-prefix, instead of executing baz action's execute() method (by default it isn't overriden in struts.xml to be something else), it will get redirected to, in this case 'dashboard.action'. Internally it uses ServletRedirectResult to do the task and read off the extension from the struts.properties.

 <!-- START SNIPPET: redirect-action-example -->
 <s:form action="baz">
     <s:textfield label="Enter your name" name="person.name"/>
     <s:submit value="Create person"/>
     <s:submit name="redirectAction:dashboard" value="Cancel"/>
 </s:form>
 <!-- END SNIPPET: redirect-action-example -->
Field Summary
protected static final  String METHOD_PREFIX     
protected static final  String ACTION_PREFIX     
protected static final  String REDIRECT_PREFIX     
protected static final  String REDIRECT_ACTION_PREFIX     
protected  boolean allowDynamicMethodCalls     
protected  boolean allowSlashesInActionNames     
protected  boolean alwaysSelectFullNamespace     
protected  PrefixTrie prefixTrie     
protected  List<String> extensions     
protected  Container container     
Constructor:
 public DefaultActionMapper() 
Method from org.apache.struts2.dispatcher.mapper.DefaultActionMapper Summary:
addParameterAction,   dropExtension,   dropExtension,   getDefaultExtension,   getMapping,   getMappingFromActionName,   getUri,   getUriFromActionMapping,   handleSpecialParameters,   isSlashesInActionNames,   parseActionName,   parseNameAndNamespace,   setAllowDynamicMethodCalls,   setAlwaysSelectFullNamespace,   setContainer,   setExtensions,   setSlashesInActionNames
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.struts2.dispatcher.mapper.DefaultActionMapper Detail:
 protected  void addParameterAction(String prefix,
    ParameterAction parameterAction) 
    Adds a parameter action. Should only be called during initialization
 protected String dropExtension(String name) 
Deprecated! Since - 2.1, use #dropExtension(java.lang.String,org.apache.struts2.dispatcher.mapper.ActionMapping) instead

    Drops the extension from the action name
 protected String dropExtension(String name,
    ActionMapping mapping) 
    Drops the extension from the action name, storing it in the mapping for later use
 protected String getDefaultExtension() 
    Returns null if no extension is specified.
 public ActionMapping getMapping(HttpServletRequest request,
    ConfigurationManager configManager) 
 public ActionMapping getMappingFromActionName(String actionName) 
 protected String getUri(HttpServletRequest request) 
    Gets the uri from the request
 public String getUriFromActionMapping(ActionMapping mapping) 
 public  void handleSpecialParameters(HttpServletRequest request,
    ActionMapping mapping) 
    Special parameters, as described in the class-level comment, are searched for and handled.
 public boolean isSlashesInActionNames() 
 protected ActionMapping parseActionName(ActionMapping mapping) 
 protected  void parseNameAndNamespace(String uri,
    ActionMapping mapping,
    ConfigurationManager configManager) 
    Parses the name and namespace from the uri
 public  void setAllowDynamicMethodCalls(String allow) 
 public  void setAlwaysSelectFullNamespace(String val) 
 public  void setContainer(Container container) 
 public  void setExtensions(String extensions) 
 public  void setSlashesInActionNames(String allow)