You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "G.L. Grobe" <ga...@grobe.net> on 2002/07/11 04:58:09 UTC

Re: WebWorkVelocityServlet

Ok, I understand this part now. What I don't get is how to have my action
(which is now a WebWorkVelocityServlet since I've changed the class it's
extended from) decide which view to return depending upon the query string
param coming in from the template page.

Below is my original action where I would compare the values of 'view' and
return a view mapping pending the value of view ...

public class Products extends ActionSupport implements ParameterAware {
   private Map params;
   ...
   public void setParameters(Map map) { this.params = map; }

   public String doExecute() throws Exception {

      if (view.equals("myview.a")) {
         return "selectA.success";
      }
      else if (view.equals("myview.b")) {
         return "selectB.success";
      }

      return "select.error";
}

Then I needed to capture the parameter from within the action (coming from
the velocity *.vm template) so I changed the class I extended from and now
have ...

public class Products extends WebWorkVelocityServlet implements
ParameterAware {
   private Map params;
   ...
   public void setParameters(Map map) { this.params = map; }

// since this is already in the VelocityServlet, it no longer exists in here
/*   public Template handleRequest(Context context) { ... */

   // but I no longer have the doExecute() I had above to decide which view
to return
   // based on the incoming parameter
}

As I understand it, I now have the handleRequest() method so that I can get
a query string parameter from the servlet now and write something like this
in the template page ...
--- *.vm file
   #if ( $reqParser.getParameter("myParam").equals("this_string") )
      ## do something
   #end

The problem is that whereas I had the execute() method from the first
ex.(extended from ActionSupport) to compare views and return a different
view pending on the value of view, I don't know how to do this (return views
pending a query string parameter in the servlet request) w/ the
WebWorkVelocityServlet.

So what I have is a query string coming from the template to the action, and
then I'll return a view mapping w/ query string parameters back to the
browser depending on the value of the incoming query string param.

I hope I explained it clearly. Thanks for your responses.


----- Original Message -----
From: "Bill Burton" <bi...@progress.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, July 10, 2002 7:56 PM
Subject: Re: [off topic] WebWorkVelocityServlet


> Hello,
>
> Part of these questions are rather general to Velocity not too WebWork
> specific so I'll try and answer them here ...
>
> "G.L. Grobe" wrote:
>
> #snip()
>
> The WebWorkVelocityServlet extends VelocityServlet.  As a result it also
> exposes the HttpServletRequest object in the Velocity context as $req.  So
> there's nothing extra you need to do to access request parameters within a
> Velocity template--just call $req.getParameter("foo") or whatever methods
> you want to call.
>
> With code below, a NullPointerException would be thrown if myParam doesn't
> exist.
>
> > By using this, I understand that I can write the following in my
velocity
> > templates ...
> >
> >    #if ( $reqParser.getParameter("myParam").equals("this_string") )
> >       ## do something
> >    #end
>
> Instead, do this ...
>     #if ( $req.getParameter("myParam") == "this_string" )
>         ## do something
>     #end
>
> -Bill
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: WebWorkVelocityServlet

Posted by "G.L. Grobe" <ga...@grobe.net>.
Bill, just now noticed you replied on the webwork list about this in another
post where I explain it a little differently. Reading it now. Thnxs!

----- Original Message -----
From: "G.L. Grobe" <ga...@grobe.net>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, July 10, 2002 9:58 PM
Subject: Re: WebWorkVelocityServlet


> Ok, I understand this part now. What I don't get is how to have my action
> (which is now a WebWorkVelocityServlet since I've changed the class it's
> extended from) decide which view to return depending upon the query string
> param coming in from the template page.
>
> Below is my original action where I would compare the values of 'view' and
> return a view mapping pending the value of view ...
>
> public class Products extends ActionSupport implements ParameterAware {
>    private Map params;
>    ...
>    public void setParameters(Map map) { this.params = map; }
>
>    public String doExecute() throws Exception {
>
>       if (view.equals("myview.a")) {
>          return "selectA.success";
>       }
>       else if (view.equals("myview.b")) {
>          return "selectB.success";
>       }
>
>       return "select.error";
> }
>
> Then I needed to capture the parameter from within the action (coming from
> the velocity *.vm template) so I changed the class I extended from and now
> have ...
>
> public class Products extends WebWorkVelocityServlet implements
> ParameterAware {
>    private Map params;
>    ...
>    public void setParameters(Map map) { this.params = map; }
>
> // since this is already in the VelocityServlet, it no longer exists in
here
> /*   public Template handleRequest(Context context) { ... */
>
>    // but I no longer have the doExecute() I had above to decide which
view
> to return
>    // based on the incoming parameter
> }
>
> As I understand it, I now have the handleRequest() method so that I can
get
> a query string parameter from the servlet now and write something like
this
> in the template page ...
> --- *.vm file
>    #if ( $reqParser.getParameter("myParam").equals("this_string") )
>       ## do something
>    #end
>
> The problem is that whereas I had the execute() method from the first
> ex.(extended from ActionSupport) to compare views and return a different
> view pending on the value of view, I don't know how to do this (return
views
> pending a query string parameter in the servlet request) w/ the
> WebWorkVelocityServlet.
>
> So what I have is a query string coming from the template to the action,
and
> then I'll return a view mapping w/ query string parameters back to the
> browser depending on the value of the incoming query string param.
>
> I hope I explained it clearly. Thanks for your responses.
>
>
> ----- Original Message -----
> From: "Bill Burton" <bi...@progress.com>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Wednesday, July 10, 2002 7:56 PM
> Subject: Re: [off topic] WebWorkVelocityServlet
>
>
> > Hello,
> >
> > Part of these questions are rather general to Velocity not too WebWork
> > specific so I'll try and answer them here ...
> >
> > "G.L. Grobe" wrote:
> >
> > #snip()
> >
> > The WebWorkVelocityServlet extends VelocityServlet.  As a result it also
> > exposes the HttpServletRequest object in the Velocity context as $req.
So
> > there's nothing extra you need to do to access request parameters within
a
> > Velocity template--just call $req.getParameter("foo") or whatever
methods
> > you want to call.
> >
> > With code below, a NullPointerException would be thrown if myParam
doesn't
> > exist.
> >
> > > By using this, I understand that I can write the following in my
> velocity
> > > templates ...
> > >
> > >    #if ( $reqParser.getParameter("myParam").equals("this_string") )
> > >       ## do something
> > >    #end
> >
> > Instead, do this ...
> >     #if ( $req.getParameter("myParam") == "this_string" )
> >         ## do something
> >     #end
> >
> > -Bill
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>