Wildcards
As an application grows in size, so will the number of action mappings. Wildcards can be used to combine similar mappings into one more generic mapping.
...
Also, the action mapping and action result properties (set using the <set-property key="foo" value="bar"> syntax) will accept wildcard-matched strings in their value attribute.
See also Wildcard Method
Parameters in namespaces
From Struts 2.1+ namespace patterns can be extracted as request parameters and bound to the action. To enable this feature, set the following constant in struts.xml:
Code Block | ||||
---|---|---|---|---|
| ||||
<constant name="struts.patternMatcher" value="named-variable"/>
|
With that in place, namespace definitions can contain {PARAM_NAME} patterns which will be evaluated against the request URL and extracted as parameters, for example:
Code Block | ||||
---|---|---|---|---|
| ||||
@Namespace{"/users/{userID}");
public class DetailsAction exends ActionSupport {
private Long userID;
public void setUserID(Long userID) {...}
}
|
If the request URL is /users/10/detail, then the DetailsAction will be executed and its userID field will be set to 10.
Warning | ||
---|---|---|
|
Note |
---|
Similar functionality can also be implemented using a custom ActionMapper. The ActionMapper will need to parse the namespace and request itself to set parameters on the matched action. The default ActonMapper is responsible for invoking the PatternMatcher. |