You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ch...@dlr.de on 2005/05/02 10:41:54 UTC

Re: how to set null value

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 <sh...@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


Re: how to set null value

Posted by jian chen <ch...@gmail.com>.
Hi, Christoph,

Thanks for sharing the background information for the null issue. It
seems to me your proposal is reasonable. Anyway, what we have done now
is to just remove the variable from the context if null is assigned to
it.

Cheers,

Jian

On 5/2/05, Christoph.Reck@dlr.de <Ch...@dlr.de> wrote:
> 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 <sh...@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
> 
>

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