velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: #set silently fails if RHS is null
Date Thu, 08 Nov 2001 05:07:10 GMT
On 11/7/01 11:43 PM, "Mike Williams" <> wrote:

>>>> On Wed, 07 Nov 2001 22:46:37 -0500,
>>>> "Geir" == "Geir Magnusson Jr." <> wrote:
> Geir> The logs don't lie.
> I value their honesty :-)
> Geir> How about
> Geir> #foreach( $item in $items )
> Geir>   #if( $item.color)
> Geir>      A $item.color $
> Geir>   #end
> Geir> #end
> Yep, that works.  However, as you may have guessed, my previous example was
> a slightly artificial one.

I suspected :)

> The actual template I'm having problems with
> has a construct like this:
> #set( $remoteName = $class.getTag("@ejb:remote-interface").getParam("name") )
> #if( $remoteName )
>   REMOTE $remoteName
> #end
> and I was hoping to avoid
> #if( $class.getTag("@ejb:remote-interface").getParam("name") )
>   REMOTE $class.getTag("@ejb:remote-interface").getParam("name")
> #end

That could be expensive...

> Should I be thinking about simplifying my model?

Maybe.  The problem is that things in the context don't have null values -
it's either in the context with a non-null value, or not in the context.

It's kind of weird to let a #set() remove something from the context, but
that is effectively what would need to happen because of our definition of
'in the context'.

However, on operations that are heavy lifting, like what I assume your
example above is, or something that changes the state of something, you
*donĀ¹t* want to do it twice.

Now, the standard, basic Context interface does support this with the
remove() [thank goodness...] so we could do it w/o any real harm.

If no one really objects, I can add this as a default-off switch to allow,
when turned on, a null value on the RHS to remove the reference from the
context, so things will behave as you expect.


Geir Magnusson Jr.                           
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message