Restful2ActionMapper

If the method is not specified (via ! or method: prefix), the method is guessed at using REST-style conventions
that examine the URL and the HTTP method.

Parameters are extracted from the action name, if parameter name/value pairs are specified using PARAM_NAME/PARAM_VALUE syntax.

These two improvements allow a GET request for category/action/movie/Thrillers to be mapped to the action
name movie with an id of Thrillers with an extra parameter named category with a value of action. A single action
mapping can then handle all CRUD operations using wildcards, e.g.

struts.mapper.idParameterName - if set, this value will be the name of the parameter under which the id is stored.
The id will then be removed from the action name. This allows restful actions to not require wildcards.

The following URL’s will invoke its methods:

Request

method called

GET: /movie/

method=”index”

GET: /movie/Thrillers

method=”view”, id=”Thrillers”

GET: /movie/Thrillers!edit

method=”edit”, id=”Thrillers”

GET: /movie/new

method=”editNew”

POST: /movie/

method=”create”

PUT: /movie/Thrillers

method=”update”, id=”Thrillers”

DELETE: /movie/Thrillers

method=”remove”, id=”Thrillers”

To simulate the HTTP methods PUT and DELETE, since they aren’t supported by HTML, the HTTP parameter __http_method
will be used.

The syntax and design for this feature was inspired by the REST support in Ruby on Rails.
See Simple RESTful support

Example

To use the Restful2ActionMapper in an existing struts application we have to change the struts.mapper.class constant
and let it point to the Restful2ActionMapper:

The problem with the above approach is that we may break existing actions because the Restful2ActionMapper tries
to guess the method name using conventions that aren’t applicable to normal action classes.

To overcome the above problem, we have to use a different action mapper depending on the url we want to process.
REST actions will be processed by the Restful2ActionMapper and non-REST actions by the DefaultActionMapper.

To achieve that we have to rely on namespaces and the PrefixBasedActionMapper that can choose which action mapper
to use for a particular url based on a prefix (the action namespace).

All other actions remain in their existing packages and namespaces we use the PrefixBasedActionMapper telling it to use
the Restful2ActionMapper for actions in the /rest namespace and the DefaultActionMapper for all other actions.