You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Ashley <ri...@hotmail.com> on 2003/03/10 16:44:35 UTC
Dynamic forward and recursion in Action's execute method
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org