Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.dispatcher.mapper
Class Restful2ActionMapper

    java.lang.Object
      org.apache.struts2.dispatcher.mapper.DefaultActionMapper
          org.apache.struts2.dispatcher.mapper.Restful2ActionMapper

All Implemented Interfaces:
  ActionMapper

    public class Restful2ActionMapper

extends DefaultActionMapper

Improved restful action mapper that adds several ReST-style improvements to action mapping, but supports fully-customized URL's via XML. The two primary ReST enhancements are:

- 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.

       <action name="movie/*" className="app.MovieAction">
         <param name="id">{0}</param>
         ...
       </action>

The following URL's will invoke its methods:

- `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/Thrillers => method="create"`
- `PUT: /movie/ => method="update"`
- `DELETE: /movie/Thrillers => method="remove"`

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 http://ryandaigle.com/articles/2006/08/01/whats-new-in-edge-rails-simply-restful-support-and-how-to-use-it

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.struts2.dispatcher.mapper.DefaultActionMapper
`DefaultActionMapper.ParameterAction`

Field Summary
`private static String` | `HTTP_METHOD_PARAM`
`protected static Log` | `LOG`

Fields inherited from class org.apache.struts2.dispatcher.mapper.DefaultActionMapper
`ACTION_PREFIX, extensions, METHOD_PREFIX, REDIRECT_ACTION_PREFIX, REDIRECT_PREFIX`

Constructor Summary
`Restful2ActionMapper()`

Method Summary
`ActionMapping` | `getMapping(HttpServletRequest request, ConfigurationManager configManager)` Expose the ActionMapping for the current request
`protected boolean` | `isDelete(HttpServletRequest request)`
`protected boolean` | `isGet(HttpServletRequest request)`
`protected boolean` | `isPost(HttpServletRequest request)`
`protected boolean` | `isPut(HttpServletRequest request)`

Methods inherited from class org.apache.struts2.dispatcher.mapper.DefaultActionMapper
`dropExtension, getDefaultExtension, getUri, getUriFromActionMapping, handleSpecialParameters, parseNameAndNamespace, setAllowDynamicMethodCalls, setAlwaysSelectFullNamespace, setContainer, setExtensions, setSlashesInActionNames`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LOG

    protected static final Log LOG

### HTTP_METHOD_PARAM

    private static final String HTTP_METHOD_PARAM

See Also:
  Constant Field Values

Constructor Detail

### Restful2ActionMapper

    public Restful2ActionMapper()

Method Detail

### getMapping

    public ActionMapping getMapping(HttpServletRequest request,
                                    ConfigurationManager configManager)

  Description copied from interface: `ActionMapper`
  Expose the ActionMapping for the current request

  Specified by:
    `getMapping` in interface `ActionMapper`
  Overrides:
    `getMapping` in class `DefaultActionMapper`
  Parameters:
    `request` - The servlet request
    `configManager` - The current configuration manager
  Returns:
    The appropriate action mapping

### isGet

    protected boolean isGet(HttpServletRequest request)

### isPost

    protected boolean isPost(HttpServletRequest request)

### isPut

    protected boolean isPut(HttpServletRequest request)

### isDelete

    protected boolean isDelete(HttpServletRequest request)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.