I know how to use wildcard method invocation within struts.xml, but is it possible to do this with annotations? If so how?
You probably have it resolved by now, but for those looking for an answer, yes it is possible.
For wildcard mapping, refer to: http://struts.apache.org/2.3.1.2/docs/wildcard-mappings.html
To read params from the url, annotate your method with this:
private String id;
@Action(value = "edit/{id}",
results={@Result(name = "success", location = "/WEB-INF/views/devices/edit.ftl")}
)
public String edit() {
// do something
return SUCCESS;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
In the case I want to redirect to a specific url, use this annotation:
@Action(value = "index",
results={@Result(name = "success", location = "/devices/edit/${entityId}", type = "redirect")}
)
You would need a getter/setter for the entityId (String in my case).
You can also have advanced wilcard mapping, namespace wildcard mapping ...
Don't forget to change the struts.xml and add the following constants.
<!-- Used for advanced wilcard mapping -->
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With