public class DefaultActionMapper extends Object implements ActionMapper
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:
<!-- 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 -->
Modifier and Type | Field and Description |
---|---|
protected static String |
ACTION_PREFIX |
protected boolean |
allowDynamicMethodCalls |
protected boolean |
allowSlashesInActionNames |
protected boolean |
alwaysSelectFullNamespace |
protected Container |
container |
protected List<String> |
extensions |
protected static String |
METHOD_PREFIX |
protected PrefixTrie |
prefixTrie |
protected static String |
REDIRECT_ACTION_PREFIX |
protected static String |
REDIRECT_PREFIX |
Constructor and Description |
---|
DefaultActionMapper() |
Modifier and Type | Method and Description |
---|---|
protected void |
addParameterAction(String prefix,
ParameterAction parameterAction)
Adds a parameter action.
|
protected String |
dropExtension(String name)
Deprecated.
Since 2.1, use
dropExtension(java.lang.String, org.apache.struts2.dispatcher.mapper.ActionMapping) instead |
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.
|
ActionMapping |
getMapping(javax.servlet.http.HttpServletRequest request,
ConfigurationManager configManager)
Expose the ActionMapping for the current request
|
ActionMapping |
getMappingFromActionName(String actionName)
Expose the ActionMapping for the specified action name
|
protected String |
getUri(javax.servlet.http.HttpServletRequest request)
Gets the uri from the request
|
String |
getUriFromActionMapping(ActionMapping mapping)
Convert an ActionMapping into a URI string
|
protected void |
handleDynamicMethod(ActionMapping mapping,
StringBuilder uri) |
protected void |
handleExtension(ActionMapping mapping,
StringBuilder uri) |
protected void |
handleName(ActionMapping mapping,
StringBuilder uri) |
protected void |
handleNamespace(ActionMapping mapping,
StringBuilder uri) |
protected void |
handleParams(ActionMapping mapping,
StringBuilder uri) |
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 String |
lookupExtension(String extension) |
protected ActionMapping |
parseActionName(ActionMapping mapping) |
protected void |
parseNameAndNamespace(String uri,
ActionMapping mapping,
ConfigurationManager configManager)
Parses the name and namespace from the uri
|
void |
setAllowDynamicMethodCalls(String allow) |
void |
setAlwaysSelectFullNamespace(String val) |
void |
setContainer(Container container) |
void |
setExtensions(String extensions) |
void |
setSlashesInActionNames(String allow) |
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 Container container
protected void addParameterAction(String prefix, ParameterAction parameterAction)
prefix
- The string prefix to trigger the actionparameterAction
- The parameter action to executepublic void setAllowDynamicMethodCalls(String allow)
public void setSlashesInActionNames(String allow)
public void setAlwaysSelectFullNamespace(String val)
public void setContainer(Container container)
public void setExtensions(String extensions)
public ActionMapping getMappingFromActionName(String actionName)
ActionMapper
getMappingFromActionName
in interface ActionMapper
actionName
- The name of the action that may have other information embedded in itpublic boolean isSlashesInActionNames()
public ActionMapping getMapping(javax.servlet.http.HttpServletRequest request, ConfigurationManager configManager)
ActionMapper
getMapping
in interface ActionMapper
request
- The servlet requestconfigManager
- The current configuration managerprotected ActionMapping parseActionName(ActionMapping mapping)
public void handleSpecialParameters(javax.servlet.http.HttpServletRequest request, ActionMapping mapping)
request
- The requestmapping
- The action mappingprotected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager)
uri
- The urimapping
- The action mapping to populateprotected String dropExtension(String name)
dropExtension(java.lang.String, org.apache.struts2.dispatcher.mapper.ActionMapping)
insteadname
- The action nameprotected String dropExtension(String name, ActionMapping mapping)
name
- The action namemapping
- The action mapping to store the extension inprotected String getDefaultExtension()
protected String getUri(javax.servlet.http.HttpServletRequest request)
request
- The requestpublic String getUriFromActionMapping(ActionMapping mapping)
ActionMapper
getUriFromActionMapping
in interface ActionMapper
mapping
- The action mappingprotected void handleNamespace(ActionMapping mapping, StringBuilder uri)
protected void handleName(ActionMapping mapping, StringBuilder uri)
protected void handleDynamicMethod(ActionMapping mapping, StringBuilder uri)
protected void handleExtension(ActionMapping mapping, StringBuilder uri)
protected void handleParams(ActionMapping mapping, StringBuilder uri)
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.