Class DefaultActionMapper
- All Implemented Interfaces:
ActionMapper
- Direct Known Subclasses:
PrefixBasedActionMapper
,Restful2ActionMapper
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
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 PrefixWith 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 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 overridden in struts.xml to be something else), the anotherAction action's execute() method (assuming again if it isn't overridden 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 action="anotherAction" value="Cancel"/> </s:form> <!-- END SNIPPET: action-example -->
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addParameterAction
(String prefix, ParameterAction parameterAction) Adds a parameter action.protected String
cleanupActionName
(String rawActionName) Checks action name against allowed pattern if not matched returns default action nameprotected String
cleanupMethodName
(String rawMethodName) Checks method name (when DMI is enabled) against allowed pattern if not matched returns default action nameprotected String
cleanupNamespaceName
(String rawNamespace) Checks namespace name against allowed pattern if not matched returns default namespaceprotected String
dropExtension
(String name, ActionMapping mapping) Drops the extension from the action name, storing it in the mapping for later useprotected void
extractMethodName
(ActionMapping mapping, ConfigurationManager configurationManager) Reads defined method name for a given action from configurationprotected String
getMapping
(jakarta.servlet.http.HttpServletRequest request, ConfigurationManager configManager) Expose the ActionMapping for the current requestgetMappingFromActionName
(String actionName) Expose the ActionMapping for the specified action namegetUriFromActionMapping
(ActionMapping mapping) Convert an ActionMapping into a URI stringprotected 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
(jakarta.servlet.http.HttpServletRequest request, ActionMapping mapping) Special parameters, as described in the class-level comment, are searched for and handled.boolean
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 urivoid
setAllowActionPrefix
(String allowActionPrefix) void
setAllowDynamicMethodCalls
(String enableDynamicMethodCalls) void
setAllowedActionNames
(String allowedActionNames) void
setAllowedMethodNames
(String allowedMethodNames) void
setAllowedNamespaceNames
(String allowedNamespaceNames) void
setAlwaysSelectFullNamespace
(String alwaysSelectFullNamespace) void
setContainer
(Container container) void
setDefaultActionName
(String defaultActionName) void
setDefaultMethodName
(String defaultMethodName) void
setDefaultNamespaceName
(String defaultNamespaceName) void
setExtensions
(String extensions) void
setSlashesInActionNames
(String enableSlashesInActionNames)
-
Field Details
-
METHOD_PREFIX
- See Also:
-
ACTION_PREFIX
- See Also:
-
allowDynamicMethodCalls
protected boolean allowDynamicMethodCalls -
allowSlashesInActionNames
protected boolean allowSlashesInActionNames -
alwaysSelectFullNamespace
protected boolean alwaysSelectFullNamespace -
prefixTrie
-
allowedNamespaceNames
-
defaultNamespaceName
-
allowedActionNames
-
defaultActionName
-
allowedMethodNames
-
defaultMethodName
-
extensions
-
container
-
-
Constructor Details
-
DefaultActionMapper
public DefaultActionMapper()
-
-
Method Details
-
addParameterAction
Adds a parameter action. Should only be called during initialization- Parameters:
prefix
- The string prefix to trigger the actionparameterAction
- The parameter action to execute- Since:
- 2.1.0
-
setAllowDynamicMethodCalls
-
setSlashesInActionNames
-
setAlwaysSelectFullNamespace
-
setAllowedNamespaceNames
-
setDefaultNamespaceName
-
setAllowedActionNames
-
setDefaultActionName
-
setAllowedMethodNames
-
setDefaultMethodName
-
setAllowActionPrefix
-
setContainer
-
setExtensions
-
getMappingFromActionName
Description copied from interface:ActionMapper
Expose the ActionMapping for the specified action name- Specified by:
getMappingFromActionName
in interfaceActionMapper
- Parameters:
actionName
- The name of the action that may have other information embedded in it- Returns:
- The appropriate action mapping
-
isSlashesInActionNames
public boolean isSlashesInActionNames() -
getMapping
public ActionMapping getMapping(jakarta.servlet.http.HttpServletRequest request, ConfigurationManager configManager) Description copied from interface:ActionMapper
Expose the ActionMapping for the current request- Specified by:
getMapping
in interfaceActionMapper
- Parameters:
request
- The servlet requestconfigManager
- The current configuration manager- Returns:
- The appropriate action mapping or null if mapping cannot be determined
-
parseActionName
-
handleSpecialParameters
public void handleSpecialParameters(jakarta.servlet.http.HttpServletRequest request, ActionMapping mapping) Special parameters, as described in the class-level comment, are searched for and handled.- Parameters:
request
- The requestmapping
- The action mapping
-
parseNameAndNamespace
protected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) Parses the name and namespace from the uri- Parameters:
uri
- The urimapping
- The action mapping to populateconfigManager
- configuration manager
-
cleanupNamespaceName
Checks namespace name against allowed pattern if not matched returns default namespace- Parameters:
rawNamespace
- name extracted from URI- Returns:
- safe namespace name
-
cleanupActionName
Checks action name against allowed pattern if not matched returns default action name- Parameters:
rawActionName
- action name extracted from URI- Returns:
- safe action name
-
cleanupMethodName
Checks method name (when DMI is enabled) against allowed pattern if not matched returns default action name- Parameters:
rawMethodName
- method name extracted from URI- Returns:
- safe method name
-
extractMethodName
Reads defined method name for a given action from configuration- Parameters:
mapping
- current instance ofActionMapping
configurationManager
- current instance ofConfigurationManager
-
dropExtension
Drops the extension from the action name, storing it in the mapping for later use- Parameters:
name
- The action namemapping
- The action mapping to store the extension in- Returns:
- The action name without its extension
-
getDefaultExtension
- Returns:
- null if no extension is specified.
-
getUriFromActionMapping
Description copied from interface:ActionMapper
Convert an ActionMapping into a URI string- Specified by:
getUriFromActionMapping
in interfaceActionMapper
- Parameters:
mapping
- The action mapping- Returns:
- The URI string that represents this mapping
-
handleNamespace
-
handleName
-
handleDynamicMethod
-
handleExtension
-
lookupExtension
-
handleParams
-