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 ActionMappers, 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 voidaddParameterAction(String prefix, ParameterAction parameterAction) Adds a parameter action.protected StringcleanupActionName(String rawActionName) Checks action name against allowed pattern if not matched returns default action nameprotected StringcleanupMethodName(String rawMethodName) Checks method name (when DMI is enabled) against allowed pattern if not matched returns default action nameprotected StringcleanupNamespaceName(String rawNamespace) Checks namespace name against allowed pattern if not matched returns default namespaceprotected StringdropExtension(String name, ActionMapping mapping) Drops the extension from the action name, storing it in the mapping for later useprotected voidextractMethodName(ActionMapping mapping, ConfigurationManager configurationManager) Reads defined method name for a given action from configurationprotected StringgetMapping(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 voidhandleDynamicMethod(ActionMapping mapping, StringBuilder uri) protected voidhandleExtension(ActionMapping mapping, StringBuilder uri) protected voidhandleName(ActionMapping mapping, StringBuilder uri) protected voidhandleNamespace(ActionMapping mapping, StringBuilder uri) protected voidhandleParams(ActionMapping mapping, StringBuilder uri) voidhandleSpecialParameters(jakarta.servlet.http.HttpServletRequest request, ActionMapping mapping) Special parameters, as described in the class-level comment, are searched for and handled.booleanprotected StringlookupExtension(String extension) protected ActionMappingparseActionName(ActionMapping mapping) protected voidparseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) Parses the name and namespace from the urivoidsetAllowActionPrefix(String allowActionPrefix) voidsetAllowDynamicMethodCalls(String enableDynamicMethodCalls) voidsetAllowedActionNames(String allowedActionNames) voidsetAllowedMethodNames(String allowedMethodNames) voidsetAllowedNamespaceNames(String allowedNamespaceNames) voidsetAlwaysSelectFullNamespace(String alwaysSelectFullNamespace) voidsetContainer(Container container) voidsetDefaultActionName(String defaultActionName) voidsetDefaultMethodName(String defaultMethodName) voidsetDefaultNamespaceName(String defaultNamespaceName) voidsetExtensions(String extensions) voidsetSlashesInActionNames(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:ActionMapperExpose the ActionMapping for the specified action name- Specified by:
getMappingFromActionNamein 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:ActionMapperExpose the ActionMapping for the current request- Specified by:
getMappingin 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 ofActionMappingconfigurationManager- 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:ActionMapperConvert an ActionMapping into a URI string- Specified by:
getUriFromActionMappingin interfaceActionMapper- Parameters:
mapping- The action mapping- Returns:
- The URI string that represents this mapping
-
handleNamespace
-
handleName
-
handleDynamicMethod
-
handleExtension
-
lookupExtension
-
handleParams
-