Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
langxml
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="strutsmymapper" class="com.mycompany.myapp.MyActionMapper" />
<constant name="struts.mapper.class" value="mymapper" />

Possible uses of the ActionMapper include defining your own, cleaner namespaces, such as URLs like /person/1, which would be similar to a request to /getPerson.action?personID=1 using the DefaultActionMapper.

...

The ActionMapper fetches the ActionMapping object corresponding to a given request. Essentially, the ActionMapping is a data transfer object that collects together details such as the Action class and method to execute. The mapping is utilized by the Dispatcher and various user interface components. It is customizable through struts.mapper.class entry in struts.properties or struts.xml. Note that the value of this constant is the name of the bean of the new mapper.

Customize

Warning

Custom ActionMapper must implement ActionMapper interface and have a default constructor.

Code Block
langxml

<bean type="org.apache.struts2.dispatcher
struts.mapper.ActionMapper" name="mymapper" class=foo.bar.MyCustomActionMapper="com.mycompany.myapp.MyActionMapper" />
<constant name="struts.mapper.class" value="mymapper" />
Code Block
public class MyCustomActionMapper implements ActionMapper {
  public ActionMapping getMapping(HttpServletRequest request, 
                                  ConfigurationManager configManager) {
    ....
  }

  public String getUriFromActionMapping(ActionMapping mapping) { 
    ....
  }
}

...