You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Michael Yartsev <an...@gmail.com> on 2008/01/01 23:19:55 UTC

Passing a url with parameters to #parse

Hello,

I am just starting out with velocity and I have a small problem I haven't
been able to solve.
Thanks in advance for any responses.

I have an index.vm file, which is divided into sections so to speak (I
didn't want to use frames).
The main content is always loaded this way:

******************************************************
            <div id="content">
                #if($params.exists("url"))
                    #parse($params.getString("url"))
                #else
                    #parse("mainContent.vm")
                #end
            </div>
******************************************************

Everything works just fine until I tried passing a url like this:

******************************************************
index.vm?url=winter08/npuzzle/makeMove.vm?piece=6
******************************************************

It's giving me an unable to find resource error because it's taking
"winter08/npuzzle/makeMove.vm?piece=6" as the name of the file
to parse, instead of parsing the " makeMove.vm" file with a parameter
named "piece".

Any ideas on what I can do?

Thanks,

-Michael

Re: Passing a url with parameters to #parse

Posted by Will Glass-Husain <wg...@gmail.com>.
The parameter can't be passed in as a URL parameter because, it's not a URL.

But you can set things in the context and pick them up later

#set($querystring = $resource.substring($resource.indexOf('?') + 1))

and then use $querystring in the #parsed file.

WILL

On Jan 3, 2008 10:20 AM, Michael Yartsev <an...@gmail.com> wrote:
> > As for stripping it in the template, you could always do:
> >
> > #set( $resource = $params.getString('url') )
> > #set( $resource = $resource.substring(0, $resource.indexOf('?')) )
> > #parse( $resource )
>
> This will only strip the parameter off the URL, I need that parameter.
> Unless I am missing something here...
>
> >You could do this with an IncludeEventHandler to modify the file
> >retrieved by #parse; whichever way is easier.
>
> I looked at the API, but I am not sure how to do this (like I said, I am
> very new to this). Could you provide a really simple example and
> I can take it from there.
>
> Thanks for your help so far guys,
>
> 2008/1/1, Will Glass-Husain <wg...@gmail.com>:
>
> >
> > You could do this with an IncludeEventHandler to modify the file
> > retrieved by #parse; whichever way is easier.
> >
> > WILL
> >
> > On Jan 1, 2008 2:57 PM, Nathan Bubna <nb...@gmail.com> wrote:
> > > Yeah, given the variety of resource loaders we have and the fact that
> > > only one of them is meant to load resources from URLs (the
> > > UrlResourceLoader), we don't have any support for parsing the resource
> > > names passed to directives like #parse or #include.  You'll have to
> > > strip out the parameter section yourself first (in the template or
> > > elsewhere) or perhaps implement an IncludeEventHandler (is that right,
> > > Will?) that does that for you.
> > >
> > > As for stripping it in the template, you could always do:
> > >
> > > #set( $resource = $params.getString('url') )
> > > #set( $resource = $resource.substring(0, $resource.indexOf('?')) )
> > > #parse( $resource )
> > >
> > > or something like that.
> > >
> > >
> > > On Jan 1, 2008 2:19 PM, Michael Yartsev <an...@gmail.com> wrote:
> > > > Hello,
> > > >
> > > > I am just starting out with velocity and I have a small problem I
> > haven't
> > > > been able to solve.
> > > > Thanks in advance for any responses.
> > > >
> > > > I have an index.vm file, which is divided into sections so to speak (I
> > > > didn't want to use frames).
> > > > The main content is always loaded this way:
> > > >
> > > > ******************************************************
> > > >             <div id="content">
> > > >                 #if($params.exists("url"))
> > > >                     #parse($params.getString("url"))
> > > >                 #else
> > > >                     #parse("mainContent.vm")
> > > >                 #end
> > > >             </div>
> > > > ******************************************************
> > > >
> > > > Everything works just fine until I tried passing a url like this:
> > > >
> > > > ******************************************************
> > > > index.vm?url=winter08/npuzzle/makeMove.vm?piece=6
> > > > ******************************************************
> > > >
> > > > It's giving me an unable to find resource error because it's taking
> > > > "winter08/npuzzle/makeMove.vm?piece=6" as the name of the file
> > > > to parse, instead of parsing the " makeMove.vm" file with a parameter
> > > > named "piece".
> > > >
> > > > Any ideas on what I can do?
> > > >
> > > > Thanks,
> > > >
> > > > -Michael
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > For additional commands, e-mail: user-help@velocity.apache.org
> > >
> > >
> >
> >
> >
> > --
> > Forio Business Simulations
> >
> > Will Glass-Husain
> > wglass@forio.com
> > www.forio.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
>



-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Passing a url with parameters to #parse

Posted by Michael Yartsev <an...@gmail.com>.
> As for stripping it in the template, you could always do:
>
> #set( $resource = $params.getString('url') )
> #set( $resource = $resource.substring(0, $resource.indexOf('?')) )
> #parse( $resource )

This will only strip the parameter off the URL, I need that parameter.
Unless I am missing something here...

>You could do this with an IncludeEventHandler to modify the file
>retrieved by #parse; whichever way is easier.

I looked at the API, but I am not sure how to do this (like I said, I am
very new to this). Could you provide a really simple example and
I can take it from there.

Thanks for your help so far guys,

2008/1/1, Will Glass-Husain <wg...@gmail.com>:
>
> You could do this with an IncludeEventHandler to modify the file
> retrieved by #parse; whichever way is easier.
>
> WILL
>
> On Jan 1, 2008 2:57 PM, Nathan Bubna <nb...@gmail.com> wrote:
> > Yeah, given the variety of resource loaders we have and the fact that
> > only one of them is meant to load resources from URLs (the
> > UrlResourceLoader), we don't have any support for parsing the resource
> > names passed to directives like #parse or #include.  You'll have to
> > strip out the parameter section yourself first (in the template or
> > elsewhere) or perhaps implement an IncludeEventHandler (is that right,
> > Will?) that does that for you.
> >
> > As for stripping it in the template, you could always do:
> >
> > #set( $resource = $params.getString('url') )
> > #set( $resource = $resource.substring(0, $resource.indexOf('?')) )
> > #parse( $resource )
> >
> > or something like that.
> >
> >
> > On Jan 1, 2008 2:19 PM, Michael Yartsev <an...@gmail.com> wrote:
> > > Hello,
> > >
> > > I am just starting out with velocity and I have a small problem I
> haven't
> > > been able to solve.
> > > Thanks in advance for any responses.
> > >
> > > I have an index.vm file, which is divided into sections so to speak (I
> > > didn't want to use frames).
> > > The main content is always loaded this way:
> > >
> > > ******************************************************
> > >             <div id="content">
> > >                 #if($params.exists("url"))
> > >                     #parse($params.getString("url"))
> > >                 #else
> > >                     #parse("mainContent.vm")
> > >                 #end
> > >             </div>
> > > ******************************************************
> > >
> > > Everything works just fine until I tried passing a url like this:
> > >
> > > ******************************************************
> > > index.vm?url=winter08/npuzzle/makeMove.vm?piece=6
> > > ******************************************************
> > >
> > > It's giving me an unable to find resource error because it's taking
> > > "winter08/npuzzle/makeMove.vm?piece=6" as the name of the file
> > > to parse, instead of parsing the " makeMove.vm" file with a parameter
> > > named "piece".
> > >
> > > Any ideas on what I can do?
> > >
> > > Thanks,
> > >
> > > -Michael
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
>
>
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: Passing a url with parameters to #parse

Posted by Will Glass-Husain <wg...@gmail.com>.
You could do this with an IncludeEventHandler to modify the file
retrieved by #parse; whichever way is easier.

WILL

On Jan 1, 2008 2:57 PM, Nathan Bubna <nb...@gmail.com> wrote:
> Yeah, given the variety of resource loaders we have and the fact that
> only one of them is meant to load resources from URLs (the
> UrlResourceLoader), we don't have any support for parsing the resource
> names passed to directives like #parse or #include.  You'll have to
> strip out the parameter section yourself first (in the template or
> elsewhere) or perhaps implement an IncludeEventHandler (is that right,
> Will?) that does that for you.
>
> As for stripping it in the template, you could always do:
>
> #set( $resource = $params.getString('url') )
> #set( $resource = $resource.substring(0, $resource.indexOf('?')) )
> #parse( $resource )
>
> or something like that.
>
>
> On Jan 1, 2008 2:19 PM, Michael Yartsev <an...@gmail.com> wrote:
> > Hello,
> >
> > I am just starting out with velocity and I have a small problem I haven't
> > been able to solve.
> > Thanks in advance for any responses.
> >
> > I have an index.vm file, which is divided into sections so to speak (I
> > didn't want to use frames).
> > The main content is always loaded this way:
> >
> > ******************************************************
> >             <div id="content">
> >                 #if($params.exists("url"))
> >                     #parse($params.getString("url"))
> >                 #else
> >                     #parse("mainContent.vm")
> >                 #end
> >             </div>
> > ******************************************************
> >
> > Everything works just fine until I tried passing a url like this:
> >
> > ******************************************************
> > index.vm?url=winter08/npuzzle/makeMove.vm?piece=6
> > ******************************************************
> >
> > It's giving me an unable to find resource error because it's taking
> > "winter08/npuzzle/makeMove.vm?piece=6" as the name of the file
> > to parse, instead of parsing the " makeMove.vm" file with a parameter
> > named "piece".
> >
> > Any ideas on what I can do?
> >
> > Thanks,
> >
> > -Michael
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>



-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Passing a url with parameters to #parse

Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, given the variety of resource loaders we have and the fact that
only one of them is meant to load resources from URLs (the
UrlResourceLoader), we don't have any support for parsing the resource
names passed to directives like #parse or #include.  You'll have to
strip out the parameter section yourself first (in the template or
elsewhere) or perhaps implement an IncludeEventHandler (is that right,
Will?) that does that for you.

As for stripping it in the template, you could always do:

#set( $resource = $params.getString('url') )
#set( $resource = $resource.substring(0, $resource.indexOf('?')) )
#parse( $resource )

or something like that.

On Jan 1, 2008 2:19 PM, Michael Yartsev <an...@gmail.com> wrote:
> Hello,
>
> I am just starting out with velocity and I have a small problem I haven't
> been able to solve.
> Thanks in advance for any responses.
>
> I have an index.vm file, which is divided into sections so to speak (I
> didn't want to use frames).
> The main content is always loaded this way:
>
> ******************************************************
>             <div id="content">
>                 #if($params.exists("url"))
>                     #parse($params.getString("url"))
>                 #else
>                     #parse("mainContent.vm")
>                 #end
>             </div>
> ******************************************************
>
> Everything works just fine until I tried passing a url like this:
>
> ******************************************************
> index.vm?url=winter08/npuzzle/makeMove.vm?piece=6
> ******************************************************
>
> It's giving me an unable to find resource error because it's taking
> "winter08/npuzzle/makeMove.vm?piece=6" as the name of the file
> to parse, instead of parsing the " makeMove.vm" file with a parameter
> named "piece".
>
> Any ideas on what I can do?
>
> Thanks,
>
> -Michael
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org