You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by ml...@amsnet.com on 2001/03/15 14:18:47 UTC

Reading QueryString in VTL


Is there an easy way to evaluate a value on the QueryString from a VTL
template?

Let's say I have some Servlet that is called as such:

http://host/SomeServlet?val1=10&val2=300

I know that I can always do something from the Servlet like:
String queryString = req.getParameter("val1");
ctx.put("queryStringval1",val1);

and I would be able to evaluate queryStringval1 from the template.

However - our designers sometimes like to throw some switches on the
QueryString to handle displays according to the switch on the QueryString.
It would be nice if the designers could have the equivalent of
req.getParameter("val1") from the template.  Is there a way to handle this?

Regards


Re: Reading QueryString in VTL

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/15/01 10:04 PM, "Geir Magnusson Jr." <ge...@optonline.net> wrote:

 Bojan Smojver wrote:
> 
> I know all of you heard this a thousand times, but how long would this
> change take if Velocity was a product of a certain software giant?

Even better...YOU could have changed the software yourself. :-)

Help US write the software you get to use. :-)

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


Re: Reading QueryString in VTL

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Bojan Smojver wrote:
> 
> I know all of you heard this a thousand times, but how long would this
> change take if Velocity was a product of a certain software giant?

More importantly, what are the odds the change would actually work as
advertised if it came from a certain software giant.....

Give it a whirl and yell if it doesn't work.  It worked for me in my
limited tests, but I am pretty pooped, and my tests were pretty limited.

The only downside is that the build now whines about the two deprecated
methods, getRealPath() and isRequestedSessionIdFromUrl().

geir


> Talking about support...
> 
> Bojan
> 
> "Geir Magnusson Jr." wrote:
> >
> > Jon Stevens wrote:
> > >
> > > Lets just create a class and use that by default. Can it even be done as an
> > > innerclass on the VelocityServlet?
> >
> > Done : the HttpServletRequest is now wrapped in a HttpServletRequestWrap
> > class before it goes into the context with the default context setup via
> > createContext()
> >
> > This allows direct access to the request methods in the template.
> >
> > geir
> >
> > --
> > Geir Magnusson Jr.                               geirm@optonline.net
> > Developing for the web?  See http://jakarta.apache.org/velocity/

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Reading QueryString in VTL

Posted by Jason van Zyl <jv...@apache.org>.
Bojan Smojver wrote:

> I know all of you heard this a thousand times, but how long would this
> change take if Velocity was a product of a certain software giant?
>
> Talking about support...
>
>

No one is faster than Geir! If Geir got a nickel for every service
pack he released then he would have more money than
that spectacled, double-speaking, truth bending,
should-have-been-shot-dead-for-propagating-basic,
coniving, weasel-faced fraud!


--
jvz.

Jason van Zyl
jvanzyl@periapt.com

http://jakarta.apache.org/velocity
http://jakarta.apache.org/turbine
http://tambora.zenplex.org



Re: Reading QueryString in VTL

Posted by Bojan Smojver <bo...@binarix.com>.
I know all of you heard this a thousand times, but how long would this
change take if Velocity was a product of a certain software giant?

Talking about support...

Bojan

"Geir Magnusson Jr." wrote:
> 
> Jon Stevens wrote:
> >
> > Lets just create a class and use that by default. Can it even be done as an
> > innerclass on the VelocityServlet?
> 
> Done : the HttpServletRequest is now wrapped in a HttpServletRequestWrap
> class before it goes into the context with the default context setup via
> createContext()
> 
> This allows direct access to the request methods in the template.
> 
> geir
> 
> --
> Geir Magnusson Jr.                               geirm@optonline.net
> Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Reading QueryString in VTL

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Jon Stevens wrote:
>
> Lets just create a class and use that by default. Can it even be done as an
> innerclass on the VelocityServlet?

Done : the HttpServletRequest is now wrapped in a HttpServletRequestWrap
class before it goes into the context with the default context setup via
createContext()

This allows direct access to the request methods in the template.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Reading QueryString in VTL

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/15/01 6:20 AM, "Geir Magnusson Jr." <ge...@optonline.net> wrote:

> Yes.  But as you may have noticed in recent discussion (and past
> discussion), there is an issue with calling some of the request methods
> directly.  This is something we will address in the near future.

Lets just create a class and use that by default. Can it even be done as an
innerclass on the VelocityServlet?

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


Re: Reading QueryString in VTL

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
mlecza@amsnet.com wrote:
> 
> Is there an easy way to evaluate a value on the QueryString from a VTL
> template?
> 
> Let's say I have some Servlet that is called as such:
> 
> http://host/SomeServlet?val1=10&val2=300
> 
> I know that I can always do something from the Servlet like:
> String queryString = req.getParameter("val1");
> ctx.put("queryStringval1",val1);
> 
> and I would be able to evaluate queryStringval1 from the template.
> 
> However - our designers sometimes like to throw some switches on the
> QueryString to handle displays according to the switch on the QueryString.
> It would be nice if the designers could have the equivalent of
> req.getParameter("val1") from the template.  Is there a way to handle this?

Yes.  But as you may have noticed in recent discussion (and past
discussion), there is an issue with calling some of the request methods
directly.  This is something we will address in the near future.

Until then (and it's prollie a good idea to do this anyway to control
what of the request object the designers have access to), just wrap 
(not the following was just typed in - not tested - for demonstrative
purposes - your mileage may vary :)

public class ReqWrap
{
	private HttpServletRequest req;

	public ReqWrap( HttpServletRequest req )
	{
		this.req = req;
	}

	public String getParameter( String val )
	{
		return req.getParameter( vel );
	}
}

and do

   ctx.put( "request", new ReqWrap( req );

The upside is you can control which parameters are asked for, or
preprocess them if you wanted to...


geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/