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]>

Reply via email to