Re: Sending dynamic parameters to a forward

2005-06-15 Thread gvanmatre
> Here's something I'm using to accomplish this:
> http://www.systemmobile.com/wp/?p=114
> It's pretty simple, but can be refit to be fairly complex.
> 

I've done something similar too, just another approach using other extension 
points in Struts.  

I extend the ActionForward adding some properties to hold the arguments.



   
   
   
   
   


I extended the ActionMapping adding a transient HttpServletRequest and 
ActionForm.   These values where staged by a base Action class.

ActionForward forward = null;
if (mapping instanceof IRusttsActionMapping) {
   ((IRusttsActionMapping) mapping).setState(form, request);
}

The extended ActionMapping had an overridden findForward that passed the 
request and form bean to the ActionForward. 

 public ActionForward findForward(String name) {

  ActionForward forward = super.findForward(name);
  if ((forward != null)
   && (forward instanceof IRusttsForwardAction)
   && (request != null)
   && (form != null)) {
   forward =
((IRusttsForwardAction) forward).stageForward(form, request);
  }

  return forward;

 }

The stageForward method of the action forward would add the parameters to the 
path.  


 /**
  * This is a factory method to handle the prorogation
  * of key arguments to the target of the action forward.
  * if the action is a redirect, a query string of encoded
  * arguments will be added to the path.  Otherwise the data
  * (Map) will be staged on the request.
  */
 public ActionForward stageForward(
  ActionForm form,
  HttpServletRequest request) {

  ActionForward targetForward = null;

  try {
   Map sourceArgs = BeanUtils.describe(form);
   String[] targetNames = getArgs();
   Map targetArgs = (Map) new TreeMap();

   for (int i = 0; i < targetNames.length; ++i) {
if (sourceArgs.containsKey(targetNames[i])) {

 Object arg = sourceArgs.get(targetNames[i]);
 if (arg != null)
  targetArgs.put(targetNames[i], arg);
 arg = null;
}
   }

   if (redirect) {
if (!targetArgs.isEmpty()) {
 StringBuffer buff = new StringBuffer(path);

 //look for an existing query string delimiter
 boolean firstArg = true;
 if (buff.toString().indexOf('?') > -1) {
  firstArg = false;
 } else
  buff.append("?");

 Iterator vi = targetArgs.keySet().iterator();
 while (vi.hasNext()) {
  String name = (String) vi.next();
  Object arg = targetArgs.get(name);
  if (arg != null) {
   String value = URLEncoder.encode(arg.toString());

   buff.append((firstArg) ? "" : "&").append(
name).append(
"=").append(
value);
   firstArg = false;
   value = null;
  }
  arg = null;
  name = null;
 }

 //build an new ActionForward with the new query 
 targetForward = new ActionForward(buff.toString(), true);

 buff = null;
 vi = null;
} else
 targetForward = this;

   } else {
//stage the data pickle in request scope for the next page  
request.setAttribute(
 com.rustts.Globals.RUSTTS_FORWARD_KEY,
 targetArgs);
targetForward = this;

   }

   targetNames = null;
   sourceArgs = null;
   targetArgs = null;
  } catch (Exception e) {
   targetForward = this;
  }

  return targetForward;
 }


It looks like a lot of code but after implemented provided a declarative way to 
handle passing parameters transparent of forward verses redirect.  

Gary


> 
> On 6/14/05, Frank W. Zammetti <[EMAIL PROTECTED]> wrote:
> > Sorry, my bad... it's not setURL, it's setPath.  It's actually a method
> > of ForwardConfig, which ActionForward extends.  Look in the third table
> > down in the link you sent, the section labeled "Methods inherited from
> > class org.apache.struts.config.ForwardConfig".
> > 
> > That's what I get for going from memory ;)
> > 
> > Frank
> > 
> > Zarar Siddiqi wrote:
> > > Where do you see the af.setURL(String) method in the ActionForward class?
> > > http://struts.apache.org/api/org/apache/struts/action/ActionForward.html
> > >
> > > I had a similar problem where dynamic values needed to be passed in via
> > > an ActionForward but I wasn't able to find something as simple as you
> > > suggest. I had to store the values in session scope (because the
> > > ActionForward had redirect=true) and then clean up the session in my
> > > receiving code.
> > >
> > > So you store the values that you are passing in session scope for a
> > > quick millisecond while you forward and then clean up once you're in the
> > > called method.
> > >
> > > Zarar
> > >
> > >
> > > - Original Message - From: "Frank W. Zammetti"
>

Re: Sending dynamic parameters to a forward

2005-06-14 Thread Nick Heudecker
Here's something I'm using to accomplish this:
http://www.systemmobile.com/wp/?p=114
It's pretty simple, but can be refit to be fairly complex.


On 6/14/05, Frank W. Zammetti <[EMAIL PROTECTED]> wrote:
> Sorry, my bad... it's not setURL, it's setPath.  It's actually a method
> of ForwardConfig, which ActionForward extends.  Look in the third table
> down in the link you sent, the section labeled "Methods inherited from
> class org.apache.struts.config.ForwardConfig".
> 
> That's what I get for going from memory ;)
> 
> Frank
> 
> Zarar Siddiqi wrote:
> > Where do you see the af.setURL(String) method in the ActionForward class?
> > http://struts.apache.org/api/org/apache/struts/action/ActionForward.html
> >
> > I had a similar problem where dynamic values needed to be passed in via
> > an ActionForward but I wasn't able to find something as simple as you
> > suggest. I had to store the values in session scope (because the
> > ActionForward had redirect=true) and then clean up the session in my
> > receiving code.
> >
> > So you store the values that you are passing in session scope for a
> > quick millisecond while you forward and then clean up once you're in the
> > called method.
> >
> > Zarar
> >
> >
> > - Original Message ----- From: "Frank W. Zammetti"
> > <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" 
> > Cc: "Struts Users Mailing List" 
> > Sent: Tuesday, June 14, 2005 9:27 AM
> > Subject: Re: Sending dynamic parameters to a forward
> >
> >
> >> You can, IIRC, append a query string to the URL returned by your
> >> forward... off the top of my head, it would look something like
> >> this... in
> >> Action 1:
> >>
> >> String param1Val = "someValue1";
> >> String param2Val = "someValue2";
> >> String queryString = "?param1=" + param1Val + "¶m2 = " + param2Val;
> >> ActionForward af = new
> >> ActionForward(mapping.findForward("ForwardToAction2"));
> >> af.setURL(af.getURL() + queryString);
> >> return af;
> >>
> >> You'll probably want to encode the parameter values, I'd suggest Commons
> >> Codec for that.
> >>
> >> --
> >> Frank W. Zammetti
> >> Founder and Chief Software Architect
> >> Omnytex Technologies
> >> http://www.omnytex.com
> >>
> >> On Tue, June 14, 2005 7:52 am, tarek.nabil said:
> >>
> >>> Hi Everyone,
> >>>
> >>> I have an action (Action1) which when completed successfully, forwards
> >>> to another action (Action2). I need to be able to send dyanamic
> >>> parameters to Action2. I thought about putting the parameters as request
> >>> attributes, but the problem here is that Action2 can be called directly
> >>> using a link from some pages and this case, the parameters will be send
> >>> as request parameters rather than attributes.
> >>>
> >>> I can write code to look in the request attributes and if not found, it
> >>> can check the request parameters, but I was hoping there's another way
> >>> to do it. I thought about setting the redirect attribute to true on this
> >>> forward but I still wouldn't know how to append parameters with dynamic
> >>> values to the forward while forwarding to it from Action1.
> >>>
> >>> Any ideas?
> >>>
> >>> -
> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> >
> 
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

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



Re: Sending dynamic parameters to a forward

2005-06-14 Thread Frank W. Zammetti
Sorry, my bad... it's not setURL, it's setPath.  It's actually a method 
of ForwardConfig, which ActionForward extends.  Look in the third table 
down in the link you sent, the section labeled "Methods inherited from 
class org.apache.struts.config.ForwardConfig".


That's what I get for going from memory ;)

Frank

Zarar Siddiqi wrote:

Where do you see the af.setURL(String) method in the ActionForward class?
http://struts.apache.org/api/org/apache/struts/action/ActionForward.html

I had a similar problem where dynamic values needed to be passed in via 
an ActionForward but I wasn't able to find something as simple as you 
suggest. I had to store the values in session scope (because the 
ActionForward had redirect=true) and then clean up the session in my 
receiving code.


So you store the values that you are passing in session scope for a 
quick millisecond while you forward and then clean up once you're in the 
called method.


Zarar


- Original Message - From: "Frank W. Zammetti" 
<[EMAIL PROTECTED]>

To: "Struts Users Mailing List" 
Cc: "Struts Users Mailing List" 
Sent: Tuesday, June 14, 2005 9:27 AM
Subject: Re: Sending dynamic parameters to a forward



You can, IIRC, append a query string to the URL returned by your
forward... off the top of my head, it would look something like 
this... in

Action 1:

String param1Val = "someValue1";
String param2Val = "someValue2";
String queryString = "?param1=" + param1Val + "¶m2 = " + param2Val;
ActionForward af = new
ActionForward(mapping.findForward("ForwardToAction2"));
af.setURL(af.getURL() + queryString);
return af;

You'll probably want to encode the parameter values, I'd suggest Commons
Codec for that.

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Tue, June 14, 2005 7:52 am, tarek.nabil said:


Hi Everyone,

I have an action (Action1) which when completed successfully, forwards
to another action (Action2). I need to be able to send dyanamic
parameters to Action2. I thought about putting the parameters as request
attributes, but the problem here is that Action2 can be called directly
using a link from some pages and this case, the parameters will be send
as request parameters rather than attributes.

I can write code to look in the request attributes and if not found, it
can check the request parameters, but I was hoping there's another way
to do it. I thought about setting the redirect attribute to true on this
forward but I still wouldn't know how to append parameters with dynamic
values to the forward while forwarding to it from Action1.

Any ideas?

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





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





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







--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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



Re: Sending dynamic parameters to a forward

2005-06-14 Thread Michael Jouravlev
On 6/14/05, Zarar Siddiqi <[EMAIL PROTECTED]> wrote:
> Where do you see the af.setURL(String) method in the ActionForward class?
> http://struts.apache.org/api/org/apache/struts/action/ActionForward.html
> 
> I had a similar problem where dynamic values needed to be passed in via an
> ActionForward but I wasn't able to find something as simple as you suggest.
> I had to store the values in session scope (because the ActionForward had
> redirect=true) and then clean up the session in my receiving code.
> 
> So you store the values that you are passing in session scope for a quick
> millisecond while you forward and then clean up once you're in the called
> method.
> 
> Zarar

This is the one that I use. To make it proper, it should be urlencoded too.

/**
 * Creates ActionForward object with URL parameters.
 *
 * @param actionMapping  action mapping object
 * @param forwardNamemapping name
 * @param urlParams  array of "key=value" strings which
 *   should be added to actionForward path
 *   as HTTP GET parameters
 *
 * @return ActionForward object with GET parameters
 */
public static ActionForward goForward(ActionMapping actionMapping,
  String forwardName,
  String[] urlParams)
{
/*
 * Find ActionForward object, defined in struts-config.xml
 */
ActionForward actionForward = actionMapping.findForward(forwardName);
if (actionForward == null) return null;

/*
 * Build URL parameters
 */
String actionPath = actionForward.getPath();
if (actionPath != null) {
for (int i = 0; i < urlParams.length; i++) {
actionPath += i==0 ? "?" : "&";
actionPath += urlParams[i];
}
}

/*
 * Create new ActionForward object. Stuts does not
 * allow to modify ActionForward objects, statically
 * defined in struts-config.xml
 */
ActionForward patchedForward =
new ActionForward(actionForward.getName(),
  actionPath,
  actionForward.getRedirect()
);

return patchedForward;
}

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



Re: Sending dynamic parameters to a forward

2005-06-14 Thread Zarar Siddiqi

Where do you see the af.setURL(String) method in the ActionForward class?
http://struts.apache.org/api/org/apache/struts/action/ActionForward.html

I had a similar problem where dynamic values needed to be passed in via an 
ActionForward but I wasn't able to find something as simple as you suggest. 
I had to store the values in session scope (because the ActionForward had 
redirect=true) and then clean up the session in my receiving code.


So you store the values that you are passing in session scope for a quick 
millisecond while you forward and then clean up once you're in the called 
method.


Zarar


- Original Message - 
From: "Frank W. Zammetti" <[EMAIL PROTECTED]>

To: "Struts Users Mailing List" 
Cc: "Struts Users Mailing List" 
Sent: Tuesday, June 14, 2005 9:27 AM
Subject: Re: Sending dynamic parameters to a forward



You can, IIRC, append a query string to the URL returned by your
forward... off the top of my head, it would look something like this... in
Action 1:

String param1Val = "someValue1";
String param2Val = "someValue2";
String queryString = "?param1=" + param1Val + "¶m2 = " + param2Val;
ActionForward af = new
ActionForward(mapping.findForward("ForwardToAction2"));
af.setURL(af.getURL() + queryString);
return af;

You'll probably want to encode the parameter values, I'd suggest Commons
Codec for that.

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Tue, June 14, 2005 7:52 am, tarek.nabil said:

Hi Everyone,

I have an action (Action1) which when completed successfully, forwards
to another action (Action2). I need to be able to send dyanamic
parameters to Action2. I thought about putting the parameters as request
attributes, but the problem here is that Action2 can be called directly
using a link from some pages and this case, the parameters will be send
as request parameters rather than attributes.

I can write code to look in the request attributes and if not found, it
can check the request parameters, but I was hoping there's another way
to do it. I thought about setting the redirect attribute to true on this
forward but I still wouldn't know how to append parameters with dynamic
values to the forward while forwarding to it from Action1.

Any ideas?

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





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





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



Re: Sending dynamic parameters to a forward

2005-06-14 Thread Frank W. Zammetti
You can, IIRC, append a query string to the URL returned by your
forward... off the top of my head, it would look something like this... in
Action 1:

String param1Val = "someValue1";
String param2Val = "someValue2";
String queryString = "?param1=" + param1Val + "¶m2 = " + param2Val;
ActionForward af = new
ActionForward(mapping.findForward("ForwardToAction2"));
af.setURL(af.getURL() + queryString);
return af;

You'll probably want to encode the parameter values, I'd suggest Commons
Codec for that.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Tue, June 14, 2005 7:52 am, tarek.nabil said:
> Hi Everyone,
>
> I have an action (Action1) which when completed successfully, forwards
> to another action (Action2). I need to be able to send dyanamic
> parameters to Action2. I thought about putting the parameters as request
> attributes, but the problem here is that Action2 can be called directly
> using a link from some pages and this case, the parameters will be send
> as request parameters rather than attributes.
>
> I can write code to look in the request attributes and if not found, it
> can check the request parameters, but I was hoping there's another way
> to do it. I thought about setting the redirect attribute to true on this
> forward but I still wouldn't know how to append parameters with dynamic
> values to the forward while forwarding to it from Action1.
>
> Any ideas?
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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



Re: Sending dynamic parameters to a forward

2005-06-14 Thread Michael Jouravlev
http://marc.theaimsgroup.com/?l=struts-user&m=111841184227894&w=2

> I have an action (Action1) which when completed successfully, forwards
> to another action (Action2). I need to be able to send dyanamic
> parameters to Action2 

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



Sending dynamic parameters to a forward

2005-06-14 Thread tarek.nabil
Hi Everyone,

I have an action (Action1) which when completed successfully, forwards
to another action (Action2). I need to be able to send dyanamic
parameters to Action2. I thought about putting the parameters as request
attributes, but the problem here is that Action2 can be called directly
using a link from some pages and this case, the parameters will be send
as request parameters rather than attributes.

I can write code to look in the request attributes and if not found, it
can check the request parameters, but I was hoping there's another way
to do it. I thought about setting the redirect attribute to true on this
forward but I still wouldn't know how to append parameters with dynamic
values to the forward while forwarding to it from Action1.

Any ideas?

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