Hello,

I have a own DispatchAction based class that should add more parameter's
dynamically to URI at runtime. Problem is that if I try to create a new ActionForward instance e.g. /my/app/myaction?method=doIt&p=100 with a new parameter, programs starts to run in recursion.


I want to do this so dynamically that I don't need struts-config.xml
to get a handle to ActionForward objects or anything else. So, is this possible in Struts or what I am doing wrong? I use Struts's version 1.1 b2.


Below is sample code of my own DispatchAction class

- r.i.a

public class MyDispatchAction extends DispatchAction
{
// Overrided execute-method
public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response)
    throws java.lang.Exception
{
  // getPath() returns e.g. /app/action.do?method=SomeAction
  String uriPath = mapping.getPath();
  StringBuffer sParams = new StringBuffer();

  // Adding another parameter dynamically.
  sParams.append(addParam(uriPath,
                           "myParam",
                           "110"));
  ActionForward fwd =
        new ActionForward(sParams.toString());

  return fwd;  // Causes recursion!!!!!
}

// Toolmethod by T.Husted
public String addParam(String path, String name, String value)
{
  StringBuffer uri = new StringBuffer(path);
  boolean isQuery = (path.indexOf("?") >= 0);

  if (isQuery)
      uri.append("&");
  else
      uri.append("?");

  uri.append(name);
  uri.append("=");
  uri.append(value);
  return uri.toString();
}

}



_________________________________________________________________
Worried what your kids see online? Protect them better with MSN 8 http://join.msn.com/?page=features/parental&pgmarket=en-gb&XAPID=186&DI=1059



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to