The better way is to define a proper data model object (value object) for your process, and pass this object as part of the request or session as necessary. The forwarded page / servlet can then check for this object and retrieve values from it as necessary.
E.g., instead of adding the "uid" to the parameter or to a the request object directly, you would instead instantiate (if necessary) a value object, set the "uid" parameter in that object, then associate that object with the request (say, using setAttribute.) In this way we avoid hacking the URL parameters, nor do we associate arbitrary objects to request or session. The only object we ever add to or retrieve from the request/session is our one data model instance. Our data model can have as many attributes as we need. Conveniently for us, Struts already provides a data model mechanism: the Form. Forms do not have to map to an actual form on an HTTP page. You can (and should) define one to pass data between related actions and JSPs. If you have a form already for those pages, you can add new attributes (such as "uid") as necessary. So suppose you have a set of pages and actions, say for a checkout process. First thing you should do is to carefully design a data model with all the attribute and methods you'll need for that entire process, including any piece of data which needs to be passed from one part of the process to another. This becomes your Form, just one for the entire process. Each action or JSP participating in the process can then simply use a subset of the Form as required. regards, -Ade ps. If you're making your own data model, don't forget to mark it as Serializable. -----Original Message----- From: Andrew Hill [mailto:[EMAIL PROTECTED]] Sent: Saturday, July 06, 2002 10:06 AM To: Struts Users Mailing List Subject: RE: Return an ActionForward with additional query data? I find I have a few places in my code that look like this: String path = StaticWebUtils.addParameterToURL(forward.getPath(),"uid","12345"); forward = new ActionForward(path,true); // Create new ActionForward with appropriate params added to path (the method it uses just determines whether to use ? or &) public static String addParameterToURL(String url, String parameter, String value) { return url + ( (url.indexOf("?")==-1) ? "?" : "&" ) + parameter + "=" + value; } I too wonder if there is a better way of doing this. -----Original Message----- From: David Mulligan [mailto:[EMAIL PROTECTED]] Sent: Friday, July 05, 2002 19:38 To: '[EMAIL PROTECTED]' Subject: Return an ActionForward with additional query data? > Is it possible to return an ActionForward with additional query > data/parameters that may arise in the Business logic of the system? > > public class UserPrefAction extends org.apache.struts.action.Action { > public ActionForward perform(......) { > String userId = request.getParameter("userId"); > //Do some database stuff here > ..... > ..... > //If success, then forward to the User Display page which is > '/settings/userDisplay.do?userId=xxxxx' > return new ActionForward("success"); > } > } > > > If my struts-config.xml > > <action path="/settings/userPref" > type=".......UserPrefAction" > scope="request" > input="/settings/userPref.vm"> > <forward name="success" path="/settings/userDisplay.do"/> > </action> > > > > The problem is that I don't know what the userId is until the > UserPrefAction is preformed. > How do/Can I create an ActionForward with query data that may arise in the > Business logic? > > Would it be logical to extend the struts framework to do use the > java.util.Message.format and do something like > > In the XML > > <forward name="success" path="/settings/userDisplay.do?userId=$1"/> > > In the Java code > > ActionForward forward = new ActionForward("success"); > forward.bind(userId); > return forward; > Where $1 would be replaced with the toString() value of the first object that is bound to the ActionForward using .bind(Object ojb) > I know it's possible to save the userId in the HttpSession, but I don't > really > want to take that path. I know as soon as I allow general access to > HttpSession > it will be used to save all types of objects between transactions. > > Thanks in advance. > Dave. -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

