You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Stephen Morris <c-...@mci.com> on 2005/05/10 02:40:47 UTC

ReferenceInsertionEvents for references in conditionals?

I'd like to generate the value of template references (e.g. $foo)  in a 
on-demand basis.

I'm using the event mechanism (a custom ReferenceInsertionEventHandler). 
I'm having trouble in templates that use a reference in, for example, an 
'#if' directive before being used outside a directive. In this case, the 
value of the reference is not available when the conditional directive 
is processed. For example:

#if ( $foo == 10 )

so the result of the if statement is always false regardless of the 
value of $foo.

Is there any way to avoid this?

Thank you.

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


Re: ReferenceInsertionEvents for references in conditionals?

Posted by Will Glass-Husain <wg...@forio.com>.
The problem is that == is checking first the type of the object and then 
calling == or equals.

I suggest you make a wrapper that performance your lazy initialization.

Set up a wrapper object so that $foo.getValue() returns the value you are 
concerned with.  Don't generate the value until the getValue() method is 
called.


WILL


----- Original Message ----- 
From: "Stephen Morris" <c-...@mci.com>
To: <ve...@jakarta.apache.org>
Sent: Monday, May 09, 2005 5:40 PM
Subject: ReferenceInsertionEvents for references in conditionals?


> I'd like to generate the value of template references (e.g. $foo)  in a 
> on-demand basis.
>
> I'm using the event mechanism (a custom ReferenceInsertionEventHandler). 
> I'm having trouble in templates that use a reference in, for example, an 
> '#if' directive before being used outside a directive. In this case, the 
> value of the reference is not available when the conditional directive is 
> processed. For example:
>
> #if ( $foo == 10 )
>
> so the result of the if statement is always false regardless of the value 
> of $foo.
>
> Is there any way to avoid this?
>
> Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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