struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "m.krueger" <mkrue...@gmx.net>
Subject ForwardDispatchAction
Date Fri, 19 Oct 2007 14:55:02 GMT

Hi,

This is an implementation of ForwardDispatchAction. It maps like
EventDispatchAction a property to value specified in the parameter's
attribute of an action, thus

<action path="/Forward"
           parameter="edit=EDIT, save=SAVE, default=EDIT">
 <forward name="EDIT" path="/someAction.do"/>
 <forward name="SAVE" path="/someOtherAction.do"/><
</action>

but it does not call a method, but the forward of the action.

<code>
public class ForwardDispatchAction extends Action {
  
  @Override
  public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response) throws
Exception {
    String forward = findForward(request, mapping.getParameter());
    
    if(forward == null) {
      throw new ServletException("No mapping found for " +
mapping.getPath());
    }
    
    return mapping.findForward(forward);
  }
  
  private String findForward(HttpServletRequest request, String parameter) {
    StringTokenizer st = new StringTokenizer(parameter, ",");
    String defaultForward = null;
    
    while(st.hasMoreTokens()) {
      String key = st.nextToken();
      String value = key;
      
      int index = key.indexOf('=');
      if(index > -1) {
        value = key.substring(index + 1).trim();
        key = key.substring(0, index).trim();
      }
      
      if(key.equals("default")) {
        defaultForward = value;
      }
      
      if(request.getParameter(key) != null) {
        return value;
      }
    }
    
    return defaultForward;
  }

}
</code>

Maybe you find this usefull.

Greetings,
   Martin

-- 
View this message in context: http://www.nabble.com/ForwardDispatchAction-tf4653813.html#a13296270
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message