You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Peter Romianowski <me...@gmx.de> on 2002/07/23 23:25:06 UTC

Stop Template Rendering

Hi there,

I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep on
the 
good job!) and have to find a possibility to stop rendering from within
the 
template. First I thought #stop would do the trick, but something like
this 
does not work

#if (...)
    some text
    #stop
#elseif (...)
    and so on
#end

I think the #stop macro is not used to stop rendering but to stop
parsing
the template. So what can I do to stop rendering from within the
template?

Thanks in advance,

Peter


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


Re: VelocityServlet.handleRequest Questions...

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/24/02 11:47 AM, "Jeff Duska" <Je...@noaa.gov> wrote:

> I've got some questions about the handleRequest method. It appears that
> in version 1.1, a new method signature was created
> 

Yep

> public Template handleRequest( HttpServletRequest, HttpServletResponse,
> Context ) replacing the previous
> public Template handleRequest( Context )
> 
> I would think that I should be using/overriding public Template
> handleRequest( HttpServletRequest, HttpServletResponse, Context )

Yep

> I noticed that both forums demo and the documentation  examples still use
> 
> public Template handleRequest(  Context context )
> {
>   HttpServletRequest request =  (HttpServletRequest) context.get(
> REQUEST );
>   HttpServletResponse response =  (HttpServletResponse) context.get(
> RESPONSE );
> 
>  ...
> }
> 
> instead of
> public Template handleRequest(  HttpServletRequest request,
> HttpServletResponse response, Context context )
> {
> 
> //  These are no longer needed
> //  HttpServletRequest request =  (HttpServletRequest) context.get(
> REQUEST );
> //  HttpServletResponse response =  (HttpServletResponse) context.get(
> RESPONSE );
> 
>  ...
> }
> 
> Is there something I've missed?

Nope.  We're just lazy and sloth-like.  We never went back because we didn't
deprecate.  Maybe we deprecate in 1.4 and get rid of it....

> I think I understand why the request
> and response are still included in the context. It is so the template
> developer has access to them.  Since you are adding all the common
> object, it makes sense do the initalization in VelocityServlet. What I
> don't understand is what did adding the request and response parameters
> gain. The developer already had access to this objects. It was the
> clearest code, but I don't think it was rocket science.

No. Clearly we aren't rocket scientists.... :)

The big difference between the two methods is that the new one allows you to
handle the request completely.

If you return 'null' from handleRequest(req, res, ctx) then VelocityServlet
will just return out of what is effectively the servlet's service method.

If you return 'null' from handleRequest(ctx) VelocityServlet will take
matters into its own hands and show the configured error() output.

geir

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



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


VelocityServlet.handleRequest Questions...

Posted by Jeff Duska <Je...@noaa.gov>.
I've got some questions about the handleRequest method. It appears that 
in version 1.1, a new method signature was created

public Template handleRequest( HttpServletRequest, HttpServletResponse, 
Context ) replacing the previous
public Template handleRequest( Context )

I would think that I should be using/overriding public Template 
handleRequest( HttpServletRequest, HttpServletResponse, Context )
I noticed that both forums demo and the documentation  examples still use
  
 public Template handleRequest(  Context context )
{
    HttpServletRequest request =  (HttpServletRequest) context.get( 
REQUEST );
    HttpServletResponse response =  (HttpServletResponse) context.get( 
RESPONSE );

   ...
}

instead of
 public Template handleRequest(  HttpServletRequest request, 
HttpServletResponse response, Context context )
{

//  These are no longer needed
//  HttpServletRequest request =  (HttpServletRequest) context.get( 
REQUEST );
//  HttpServletResponse response =  (HttpServletResponse) context.get( 
RESPONSE );

   ...
}

Is there something I've missed?  I think I understand why the request 
and response are still included in the context. It is so the template 
developer has access to them.  Since you are adding all the common 
object, it makes sense do the initalization in VelocityServlet. What I 
don't understand is what did adding the request and response parameters 
gain. The developer already had access to this objects. It was the 
clearest code, but I don't think it was rocket science.


Thanks,

Jeff Duska



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


Re: AW: AW: Stop Template Rendering

Posted by Simon Christian <si...@cpd.co.uk>.
Ok thought that might be the case. You're probably best off using the 
#if( !$finished ) technique you suggested. I wouldn't worry about having 
a lot more of the template processed - we all know how fast Velocity is 
:) and it's only having to do a (very quick) test on a boolean value in 
each case.

- simon

Peter Romianowski wrote:
> Hi,
> 
> That came into my mind, too. But I have really many conditions
> for each value ($email, $firstname ...).
> 
> Thanks anyway!
> 
> Peter
> 
> -----Ursprüngliche Nachricht-----
> Von: Simon Christian [mailto:simon@cpd.co.uk] 
> Gesendet: Mittwoch, 24. Juli 2002 14:08
> An: Velocity Users List
> Betreff: Re: AW: Stop Template Rendering
> 
> 
> Hi Peter,
> 
> This may not deal with all cases, but the snippet you included could be 
> replaced by something like:
> 
> #if( $email && $email.startsWith("pero") )
>    print something
> #elseif( $firstname && $firstname = "Peter" )
>    print some text
> #end
> 
> 
> - simon
> 
> 
> Peter Romianowski wrote:
> 
>>Hi,
>>
>>I will try 1.3.1-rc1 to see if my whole application (doing a lot of 
>>things with this neat thing called velocity :) is working. BTW is the 
>>bug dealing
>>with literal long and double values fixed?
>>
>>I have a velocity-page that contains of a lot of distinct 
>>#if-statements in the style of:
>>
>>#if ($email)
>>    #if ($email.startsWith("pero")
>>        print something and exit
>>        #stop
>>    #end
>>    #if
>>        ...
>>    #end
>>#end
>>
>>#if ($firstname))
>>    #if ($firstname = "Peter")
>>        print some text and exit
>>        #stop
>>    #end
>>#end
>>
>>So the rendering should stop if one of the (many) nested conditions is
> 
> 
>>true. Note that I cannot use a #elseif-Statement here. My workaround 
>>would be to doing something like:
>>
>>#set ($finished = true)
>>
>>instead of the #stop-thing and then continue like this:
>>
>>#if (!$finished && $firstname)
>>...
>>
>>That would work, but there would be a lot more code processed than 
>>needed. I would not like to split this, because the conditions should 
>>be readable and
>>understandable.
>>
>>So, if you have a nicer idea, I would love to hear it. Otherwise I 
>>could live with the $finished-thing.
>>
>>Thanks for your reply!
>>
>>Peter
>>
>>
>>
>>>Hi there,
>>>
>>>I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep on
>>
>>
>>>the good job!) and have to find a possibility to stop rendering from
>>>within the
>>
>>
>>Can you try 1.3.1-rc1 to verify it's ok?
>>
>>
>>
>>>template. First I thought #stop would do the trick, but something like
>>
>>
>>>this does not work
>>>
>>>#if (...)
>>> some text
>>> #stop
>>>#elseif (...)
>>> and so on
>>>#end
>>>
>>>I think the #stop macro is not used to stop rendering but to stop
>>>parsing the template. So what can I do to stop rendering from within 
>>>the template?
>>>
>>
>>
>>Stop doesn't work.  Why do you want to stop?  Depending on that 
>>answer, maybe you factor your templates into pieces, and then assemble
> 
> 
>>conditionally?
>>
>>
> 
> 


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


Re: AW: AW: Stop Template Rendering

Posted by Jim Seach <jw...@yahoo.com>.
Peter,

If you have complex conditions, another way to handle it may be to
create a variable that reflects the condition then use it later in an
#if, #elseif.  For example, set a context variable called
$DisplayChoice to reflect the complex logic:

#set ($DisplayChoice = 1) ## default

#if ($email)
    #if ($email.startsWith("pero")
      #set ($DisplayChoice = 2)
    #end
    #if
        ...
    #end
#end

#if ($firstname))
    #if ($firstname = "Peter")
      #set ($DisplayChoice = 3)
    #end
#end


Then later in the page, use $DisplayChoice in a simple #if, #elseif
sequence to render the results:

#if ($DisplayChoice == 1)
  display output for choice 1
#elseif ($DisplayChoice == 2)
  display output for choice 2
#elseif ($DisplayChoice == 3)
  display output for choice 3
#end
    
This also makes it easier to see your conditional logic.

Hope that helps,

Jim Seach


--- Peter Romianowski <me...@gmx.de> wrote:
> Hi,
> 
> That came into my mind, too. But I have really many conditions
> for each value ($email, $firstname ...).
> 
> Thanks anyway!
> 
> Peter
> 
> -----Urspr�ngliche Nachricht-----
> Von: Simon Christian [mailto:simon@cpd.co.uk] 
> Gesendet: Mittwoch, 24. Juli 2002 14:08
> An: Velocity Users List
> Betreff: Re: AW: Stop Template Rendering
> 
> 
> Hi Peter,
> 
> This may not deal with all cases, but the snippet you included could
> be 
> replaced by something like:
> 
> #if( $email && $email.startsWith("pero") )
>    print something
> #elseif( $firstname && $firstname = "Peter" )
>    print some text
> #end
> 
> 
> - simon
> 
> 
> Peter Romianowski wrote:
> > Hi,
> > 
> > I will try 1.3.1-rc1 to see if my whole application (doing a lot of
> 
> > things with this neat thing called velocity :) is working. BTW is
> the 
> > bug dealing
> > with literal long and double values fixed?
> > 
> > I have a velocity-page that contains of a lot of distinct 
> > #if-statements in the style of:
> > 
> > #if ($email)
> >     #if ($email.startsWith("pero")
> >         print something and exit
> >         #stop
> >     #end
> >     #if
> >         ...
> >     #end
> > #end
> > 
> > #if ($firstname))
> >     #if ($firstname = "Peter")
> >         print some text and exit
> >         #stop
> >     #end
> > #end
> > 
> > So the rendering should stop if one of the (many) nested conditions
> is
> 
> > true. Note that I cannot use a #elseif-Statement here. My
> workaround 
> > would be to doing something like:
> > 
> > #set ($finished = true)
> > 
> > instead of the #stop-thing and then continue like this:
> > 
> > #if (!$finished && $firstname)
> > ...
> > 
> > That would work, but there would be a lot more code processed than 
> > needed. I would not like to split this, because the conditions
> should 
> > be readable and
> > understandable.
> > 
> > So, if you have a nicer idea, I would love to hear it. Otherwise I 
> > could live with the $finished-thing.
> > 
> > Thanks for your reply!
> > 
> > Peter
> > 
> > 
> >>Hi there,
> >>
> >>I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep
> on
> > 
> > 
> >>the good job!) and have to find a possibility to stop rendering
> from
> >>within the
> > 
> > 
> > Can you try 1.3.1-rc1 to verify it's ok?
> > 
> > 
> >>template. First I thought #stop would do the trick, but something
> like
> > 
> > 
> >>this does not work
> >>
> >>#if (...)
> >>  some text
> >>  #stop
> >>#elseif (...)
> >>  and so on
> >>#end
> >>
> >>I think the #stop macro is not used to stop rendering but to stop
> >>parsing the template. So what can I do to stop rendering from
> within 
> >>the template?
> >>
> > 
> > 
> > Stop doesn't work.  Why do you want to stop?  Depending on that 
> > answer, maybe you factor your templates into pieces, and then
> assemble
> 
> > conditionally?
> > 
> > 
> 
> 
> --
> 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>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

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


AW: AW: Stop Template Rendering

Posted by Peter Romianowski <me...@gmx.de>.
Hi,

That came into my mind, too. But I have really many conditions
for each value ($email, $firstname ...).

Thanks anyway!

Peter

-----Ursprüngliche Nachricht-----
Von: Simon Christian [mailto:simon@cpd.co.uk] 
Gesendet: Mittwoch, 24. Juli 2002 14:08
An: Velocity Users List
Betreff: Re: AW: Stop Template Rendering


Hi Peter,

This may not deal with all cases, but the snippet you included could be 
replaced by something like:

#if( $email && $email.startsWith("pero") )
   print something
#elseif( $firstname && $firstname = "Peter" )
   print some text
#end


- simon


Peter Romianowski wrote:
> Hi,
> 
> I will try 1.3.1-rc1 to see if my whole application (doing a lot of 
> things with this neat thing called velocity :) is working. BTW is the 
> bug dealing
> with literal long and double values fixed?
> 
> I have a velocity-page that contains of a lot of distinct 
> #if-statements in the style of:
> 
> #if ($email)
>     #if ($email.startsWith("pero")
>         print something and exit
>         #stop
>     #end
>     #if
>         ...
>     #end
> #end
> 
> #if ($firstname))
>     #if ($firstname = "Peter")
>         print some text and exit
>         #stop
>     #end
> #end
> 
> So the rendering should stop if one of the (many) nested conditions is

> true. Note that I cannot use a #elseif-Statement here. My workaround 
> would be to doing something like:
> 
> #set ($finished = true)
> 
> instead of the #stop-thing and then continue like this:
> 
> #if (!$finished && $firstname)
> ...
> 
> That would work, but there would be a lot more code processed than 
> needed. I would not like to split this, because the conditions should 
> be readable and
> understandable.
> 
> So, if you have a nicer idea, I would love to hear it. Otherwise I 
> could live with the $finished-thing.
> 
> Thanks for your reply!
> 
> Peter
> 
> 
>>Hi there,
>>
>>I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep on
> 
> 
>>the good job!) and have to find a possibility to stop rendering from
>>within the
> 
> 
> Can you try 1.3.1-rc1 to verify it's ok?
> 
> 
>>template. First I thought #stop would do the trick, but something like
> 
> 
>>this does not work
>>
>>#if (...)
>>  some text
>>  #stop
>>#elseif (...)
>>  and so on
>>#end
>>
>>I think the #stop macro is not used to stop rendering but to stop
>>parsing the template. So what can I do to stop rendering from within 
>>the template?
>>
> 
> 
> Stop doesn't work.  Why do you want to stop?  Depending on that 
> answer, maybe you factor your templates into pieces, and then assemble

> conditionally?
> 
> 


--
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: AW: Stop Template Rendering

Posted by Simon Christian <si...@cpd.co.uk>.
Hi Peter,

This may not deal with all cases, but the snippet you included could be 
replaced by something like:

#if( $email && $email.startsWith("pero") )
   print something
#elseif( $firstname && $firstname = "Peter" )
   print some text
#end


- simon


Peter Romianowski wrote:
> Hi,
> 
> I will try 1.3.1-rc1 to see if my whole application (doing a lot of
> things
> with this neat thing called velocity :) is working. BTW is the bug
> dealing 
> with literal long and double values fixed?
> 
> I have a velocity-page that contains of a lot of distinct #if-statements
> in the style of:
> 
> #if ($email)
>     #if ($email.startsWith("pero")
>         print something and exit
>         #stop
>     #end
>     #if
>         ...
>     #end
> #end
> 
> #if ($firstname))
>     #if ($firstname = "Peter")
>         print some text and exit
>         #stop
>     #end
> #end
> 
> So the rendering should stop if one of the (many) nested conditions is
> true. Note that I cannot use a #elseif-Statement here. My workaround
> would
> be to doing something like:
> 
> #set ($finished = true)
> 
> instead of the #stop-thing and then continue like this:
> 
> #if (!$finished && $firstname)
> ...
> 
> That would work, but there would be a lot more code processed than
> needed.
> I would not like to split this, because the conditions should be
> readable and
> understandable.
> 
> So, if you have a nicer idea, I would love to hear it. Otherwise I could
> live
> with the $finished-thing.
> 
> Thanks for your reply!
> 
> Peter
> 
> 
>>Hi there,
>>
>>I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep on
> 
> 
>>the good job!) and have to find a possibility to stop rendering from 
>>within the
> 
> 
> Can you try 1.3.1-rc1 to verify it's ok?
> 
> 
>>template. First I thought #stop would do the trick, but something like
> 
> 
>>this does not work
>>
>>#if (...)
>>  some text
>>  #stop
>>#elseif (...)
>>  and so on
>>#end
>>
>>I think the #stop macro is not used to stop rendering but to stop 
>>parsing the template. So what can I do to stop rendering from within 
>>the template?
>>
> 
> 
> Stop doesn't work.  Why do you want to stop?  Depending on that answer,
> maybe you factor your templates into pieces, and then assemble
> conditionally?
> 
> 


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


AW: Stop Template Rendering

Posted by Peter Romianowski <me...@gmx.de>.
Hi,

I will try 1.3.1-rc1 to see if my whole application (doing a lot of
things
with this neat thing called velocity :) is working. BTW is the bug
dealing 
with literal long and double values fixed?

I have a velocity-page that contains of a lot of distinct #if-statements
in the style of:

#if ($email)
    #if ($email.startsWith("pero")
        print something and exit
        #stop
    #end
    #if
        ...
    #end
#end

#if ($firstname))
    #if ($firstname = "Peter")
        print some text and exit
        #stop
    #end
#end

So the rendering should stop if one of the (many) nested conditions is
true. Note that I cannot use a #elseif-Statement here. My workaround
would
be to doing something like:

#set ($finished = true)

instead of the #stop-thing and then continue like this:

#if (!$finished && $firstname)
...

That would work, but there would be a lot more code processed than
needed.
I would not like to split this, because the conditions should be
readable and
understandable.

So, if you have a nicer idea, I would love to hear it. Otherwise I could
live
with the $finished-thing.

Thanks for your reply!

Peter

> Hi there,
> 
> I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep on

> the good job!) and have to find a possibility to stop rendering from 
> within the

Can you try 1.3.1-rc1 to verify it's ok?

> template. First I thought #stop would do the trick, but something like

> this does not work
> 
> #if (...)
>   some text
>   #stop
> #elseif (...)
>   and so on
> #end
> 
> I think the #stop macro is not used to stop rendering but to stop 
> parsing the template. So what can I do to stop rendering from within 
> the template?
> 

Stop doesn't work.  Why do you want to stop?  Depending on that answer,
maybe you factor your templates into pieces, and then assemble
conditionally?



-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
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: Stop Template Rendering

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/23/02 5:25 PM, "Peter Romianowski" <me...@gmx.de> wrote:

> Hi there,
> 
> I am using Velocity 1.2 (waiting for 1.3.1 to upgrade finally, keep on
> the 
> good job!) and have to find a possibility to stop rendering from within
> the 

Can you try 1.3.1-rc1 to verify it's ok?

> template. First I thought #stop would do the trick, but something like
> this 
> does not work
> 
> #if (...)
>   some text
>   #stop
> #elseif (...)
>   and so on
> #end
> 
> I think the #stop macro is not used to stop rendering but to stop
> parsing
> the template. So what can I do to stop rendering from within the
> template?
> 

Stop doesn't work.  Why do you want to stop?  Depending on that answer,
maybe you factor your templates into pieces, and then assemble
conditionally?
-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



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