Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.dispatcher.mapper
Class DefaultActionMapper

    java.lang.Object
      org.apache.struts2.dispatcher.mapper.DefaultActionMapper

All Implemented Interfaces:
  ActionMapper

Direct Known Subclasses:
  PrefixBasedActionMapper, Restful2ActionMapper

    public class DefaultActionMapper

extends java.lang.Object
implements ActionMapper

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:

- Method prefix - method:default

- Action prefix - action:dashboard

- Redirect prefix - redirect:cancel.jsp

- Redirect-action prefix - redirectAction:cancel

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 java.lang.String` | `ACTION_PREFIX`
`protected boolean` | `allowDynamicMethodCalls`
`protected boolean` | `allowSlashesInActionNames`
`protected boolean` | `alwaysSelectFullNamespace`
`protected Container` | `container`
`protected java.util.List<java.lang.String>` | `extensions`
`protected static java.lang.String` | `METHOD_PREFIX`
`protected PrefixTrie` | `prefixTrie`
`protected static java.lang.String` | `REDIRECT_ACTION_PREFIX`
`protected static java.lang.String` | `REDIRECT_PREFIX`

Constructor Summary
`DefaultActionMapper()`

Method Summary
`protected void` | `addParameterAction(java.lang.String prefix, ParameterAction parameterAction)` Adds a parameter action.
`protected java.lang.String` | `dropExtension(java.lang.String name)` Deprecated. Since 2.1, use `dropExtension(java.lang.String,org.apache.struts2.dispatcher.mapper.ActionMapping)` instead
`protected java.lang.String` | `dropExtension(java.lang.String name, ActionMapping mapping)` Drops the extension from the action name, storing it in the mapping for later use
`protected java.lang.String` | `getDefaultExtension()` Returns null if no extension is specified.
`ActionMapping` | `getMapping(javax.servlet.http.HttpServletRequest request, ConfigurationManager configManager)` Expose the ActionMapping for the current request
`ActionMapping` | `getMappingFromActionName(java.lang.String actionName)` Expose the ActionMapping for the specified action name
`protected java.lang.String` | `getUri(javax.servlet.http.HttpServletRequest request)` Gets the uri from the request
`java.lang.String` | `getUriFromActionMapping(ActionMapping mapping)` Convert an ActionMapping into a URI string
`void` | `handleSpecialParameters(javax.servlet.http.HttpServletRequest request, ActionMapping mapping)` Special parameters, as described in the class-level comment, are searched for and handled.
`boolean` | `isSlashesInActionNames()`
`protected ActionMapping` | `parseActionName(ActionMapping mapping)`
`protected void` | `parseNameAndNamespace(java.lang.String uri, ActionMapping mapping, ConfigurationManager configManager)` Parses the name and namespace from the uri
`void` | `setAllowDynamicMethodCalls(java.lang.String allow)`
`void` | `setAlwaysSelectFullNamespace(java.lang.String val)`
`void` | `setContainer(Container container)`
`void` | `setExtensions(java.lang.String extensions)`
`void` | `setSlashesInActionNames(java.lang.String allow)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### METHOD_PREFIX

    protected static final java.lang.String METHOD_PREFIX

See Also:
  Constant Field Values

### ACTION_PREFIX

    protected static final java.lang.String ACTION_PREFIX

See Also:
  Constant Field Values

### REDIRECT_PREFIX

    protected static final java.lang.String REDIRECT_PREFIX

See Also:
  Constant Field Values

### REDIRECT_ACTION_PREFIX

    protected static final java.lang.String REDIRECT_ACTION_PREFIX

See Also:
  Constant Field Values

### allowDynamicMethodCalls

    protected boolean allowDynamicMethodCalls

### allowSlashesInActionNames

    protected boolean allowSlashesInActionNames

### alwaysSelectFullNamespace

    protected boolean alwaysSelectFullNamespace

### prefixTrie

    protected PrefixTrie prefixTrie

### extensions

    protected java.util.List<java.lang.String> extensions

### container

    protected Container container

Constructor Detail

### DefaultActionMapper

    public DefaultActionMapper()

Method Detail

### addParameterAction

    protected void addParameterAction(java.lang.String prefix,
                                      ParameterAction parameterAction)

  Adds a parameter action. Should only be called during initialization

  Parameters:
    `prefix` - The string prefix to trigger the action
    `parameterAction` - The parameter action to execute
  Since:
    2.1.0

### setAllowDynamicMethodCalls

    public void setAllowDynamicMethodCalls(java.lang.String allow)

### setSlashesInActionNames

    public void setSlashesInActionNames(java.lang.String allow)

### setAlwaysSelectFullNamespace

    public void setAlwaysSelectFullNamespace(java.lang.String val)

### setContainer

    public void setContainer(Container container)

### setExtensions

    public void setExtensions(java.lang.String extensions)

### getMappingFromActionName

    public ActionMapping getMappingFromActionName(java.lang.String actionName)

  Description copied from interface: `ActionMapper`
  Expose the ActionMapping for the specified action name

  Specified by:
    `getMappingFromActionName` in interface `ActionMapper`
  Parameters:
    `actionName` - The name of the action that may have other information embedded in it
  Returns:
    The appropriate action mapping

### getMapping

    public ActionMapping getMapping(javax.servlet.http.HttpServletRequest request,
                                    ConfigurationManager configManager)

  Description copied from interface: `ActionMapper`
  Expose the ActionMapping for the current request

  Specified by:
    `getMapping` in interface `ActionMapper`
  Parameters:
    `request` - The servlet request
    `configManager` - The current configuration manager
  Returns:
    The appropriate action mapping

### parseActionName

    protected ActionMapping parseActionName(ActionMapping mapping)

### handleSpecialParameters

    public void handleSpecialParameters(javax.servlet.http.HttpServletRequest request,
                                        ActionMapping mapping)

  Special parameters, as described in the class-level comment, are searched for and handled.

  Parameters:
    `request` - The request
    `mapping` - The action mapping

### parseNameAndNamespace

    protected void parseNameAndNamespace(java.lang.String uri,
                                         ActionMapping mapping,
                                         ConfigurationManager configManager)

  Parses the name and namespace from the uri

  Parameters:
    `uri` - The uri
    `mapping` - The action mapping to populate

### dropExtension

    protected java.lang.String dropExtension(java.lang.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

  Parameters:
    `name` - The action name
  Returns:
    The action name without its extension

### dropExtension

    protected java.lang.String dropExtension(java.lang.String name,
                                             ActionMapping mapping)

  Drops the extension from the action name, storing it in the mapping for later use

  Parameters:
    `name` - The action name
    `mapping` - The action mapping to store the extension in
  Returns:
    The action name without its extension

### getDefaultExtension

    protected java.lang.String getDefaultExtension()

  Returns null if no extension is specified.

### getUri

    protected java.lang.String getUri(javax.servlet.http.HttpServletRequest request)

  Gets the uri from the request

  Parameters:
    `request` - The request
  Returns:
    The uri

### getUriFromActionMapping

    public java.lang.String getUriFromActionMapping(ActionMapping mapping)

  Description copied from interface: `ActionMapper`
  Convert an ActionMapping into a URI string

  Specified by:
    `getUriFromActionMapping` in interface `ActionMapper`
  Parameters:
    `mapping` - The action mapping
  Returns:
    The URI string that represents this mapping

### isSlashesInActionNames

    public boolean isSlashesInActionNames()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.