You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Alfors <pe...@hksystems.com> on 2000/10/10 15:04:43 UTC

Re: Can I pass some dynamic parameter via Action class?

Hello Jung,

This is one method to add a query string to your action forward.

  public ActionForward perform(ActionMapping pMapping,
                                ActionForm pForm,
                                HttpServletRequest pRequest,
                                HttpServletResponse pResponse)
     throws IOException, ServletException
  {

            ... <action class code> ...

            ActionForward actionForward = new ActionForward();

actionForward.setPath(pMapping.findForward("success").getPath() +
"?key1=" + value1);
            return actionForward;
  }

However, there may be a better method out there.

Pete


Re: Can I pass some dynamic parameter via Action class?

Posted by Peter Alfors <pe...@hksystems.com>.
Hi Jason,

    You are correct.  For most situations, we place parameters in request
attributes.  However, there is an instance in which we chose to use query
strings...

We have a page that is a list of items for the user to choose from.  Each item
consists of a link with a query string that points to an action class
(ActionRow.do?id=1).  The ActionRow class then displays a detail page for the
specified item ID.

In addition, we allow users to add new items.  The 'add' page calls an action
class (ActionAdd.do) to perform the actual addition to the database.  Upon
success, we forward the user to the detail page (ActionRow.do) for the new
item.  Since the ActionRow class is expecting the item ID to be in the query
string (as it is in the list page), we then add the query string to the action
forward before returning from the ActionAdd action class.

Granted, there are other options available to us.  We could have the item
detail action check both the request attribute and the query string.  Or we
could have separate action classes.

I would be interested in hearing other options that may provide a better
solution.  After all, we are always ready to learn something new!

Pete



Jason Kitchen wrote:

> Peter Alfors wrote:
> >
> > Hello Jung,
> >
> > This is one method to add a query string to your action forward.
> >
> >   public ActionForward perform(ActionMapping pMapping,
> >                                 ActionForm pForm,
> >                                 HttpServletRequest pRequest,
> >                                 HttpServletResponse pResponse)
> >      throws IOException, ServletException
> >   {
> >
> >             ... <action class code> ...
> >
> >             ActionForward actionForward = new ActionForward();
> >
> > actionForward.setPath(pMapping.findForward("success").getPath() +
> > "?key1=" + value1);
> >             return actionForward;
> >   }
> >
> > However, there may be a better method out there.
> >
> > Pete
>
> Since the forward is internal to the webserver rather than a redirect there
> doesn't seem to be much point in putting this onto the URL. Why don't you
> just put the parameters directly onto the request ?
>
> request.setAttribute("key1", value1);
> return pMapping.findForward("success");
>
> -- Jason

Re: Can I pass some dynamic parameter via Action class?

Posted by Jason Kitchen <ja...@s1.com>.
Peter Alfors wrote:
> 
> Hello Jung,
> 
> This is one method to add a query string to your action forward.
> 
>   public ActionForward perform(ActionMapping pMapping,
>                                 ActionForm pForm,
>                                 HttpServletRequest pRequest,
>                                 HttpServletResponse pResponse)
>      throws IOException, ServletException
>   {
> 
>             ... <action class code> ...
> 
>             ActionForward actionForward = new ActionForward();
> 
> actionForward.setPath(pMapping.findForward("success").getPath() +
> "?key1=" + value1);
>             return actionForward;
>   }
> 
> However, there may be a better method out there.
> 
> Pete

Since the forward is internal to the webserver rather than a redirect there
doesn't seem to be much point in putting this onto the URL. Why don't you
just put the parameters directly onto the request ?

request.setAttribute("key1", value1);
return pMapping.findForward("success");

-- Jason