velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: how to set null value
Date Mon, 02 May 2005 08:41:54 GMT
The reson for not allowing a null in the context was the original
implementation with a Hashtable backed context, which did not allow
nulls. The original designers thought that other implementations
should also be shielded from dealing with null values, eg. databases
(also CORBA) often can't.

Now with Java > 1.2 and collections and Maps, this is not true any
more for the general case. Due to the [unexpected] result of not
changing the context when setting the value to null, changing
the behaviour is a backward-compatibility issue.

Therefore I originally proposed to allow the bang character in the
#set( $!bar = $!foo ) directive to:
a) avoid logging the null from $!foo (this is current behaviour
    when rendering foo)
b) allowing setting the context to null with then ban in $!bar
I sent a patch many years ago (was rejected, event though it is BC).

I suggest to recreate a patch with the #set( $!bar = ... ) syntax
for allowing nulls in the context (if a NPE is throuwn by the
context, then do internalRemove), and get this into the velocity
core :)

Cheers,
Christoph


Shinobu Kawai wrote:
> Hi Jian,
> 
> 
>>Thanks for sending me the useful information. After much
>>investigation, I plan to do the following hack for setting null value
>>in the context:
>>
>>1) In the ASTSetDirective, in the render method, comment out the if block
>>       if ( value  == null)
>>       {
>>         ....
>>Basically, this will allow the set null process to go ahread.
>>
>>2) in the AbstractContext, remove the key from the context if the
>>value to be set is null:
>>
>>       else if (value == null)
>>       {
>>           this.internalRemove(key);
>>           return null;
>>       }
>>
>>So, this should remove the variable in the context if it is assigned a
>>null value,
> 
> 
> I believe so.
> 
> 
>>and it will be consistent with future release in Velocity,
>>right?
> 
> 
> Can't be sure about that.  The community has not yet reached consensus
> on what to do with this issue.
> 
> Best regards,
> -- Shinobu
> 
> --
> Shinobu Kawai <shinobu.kawai@gmail.com>
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message