You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Shinobu Kawai <sh...@gmail.com> on 2004/12/04 16:11:43 UTC

RFE: null support

Hi all,

If Velocity were to support null, how would you expect it to behave?


Some thoughts:

1. The word "null" should be treated as null in Velocity specific content.

eg.
#set ($list = ["one", null, "three"])
should make a 3 element list, with the elements "one", null and "three".

$foo.bar(null)
should call the "bar" method of the "foo" object with a null parameter.


2. The "set" directive should accept null value as the RHS.

eg.
Assuming that $bar wasn't in the Context,
#set ($foo = $bar)
#set ($foo = null)
should both remove "foo" from the Context.


3. The "foreach" directive should set null when the element is null. 
Currently, it preserves the last element.

eg.
#set ($list = ["one", null, "three"])
#foreach ($foo in $list)
$!foo
#end
should output:
one

three


4. The "if" directive should be able to compare references with null.

eg.
#if ($foo == null)
foo is null
#end
should output
foo is null
if foo was not in the Context.

if ($foo != null)
foo is not null
#end
should output
foo is not null
if foo was in the Context.


Any comments, opinions, etc.?

Related bugzilla issues:
  http://issues.apache.org/bugzilla/show_bug.cgi?id=20999
  http://issues.apache.org/bugzilla/show_bug.cgi?id=27741
Related list postings:
  http://nagoya.apache.org/eyebrowse/BrowseList?listName=velocity-user@jakarta.apache.org&by=thread&from=949954

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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


Re: RFE: null support

Posted by Shinobu Kawai <sh...@gmail.com>.
Thanks for all of your input, everyone!

> If Velocity were to support null, how would you expect it to behave?

I'll try to sum it up into a new Wiki page, under the "Architecture
Discussions & Debates" section.
   http://wiki.apache.org/jakarta-velocity/
## VelocityNullSupport, maybe?

I also want to put workarounds for the current version users.

I'm trying to figure out the EventCartridge way, but without success. 
In bugzilla #20999, Dan said:
---- bugzilla #20999 excerpt from here ----
------- Additional Comment #5 From Daniel Rall 2003-08-22 23:05 [reply] ------- 
This can already be accomplished via an EventCartridge.

------- Additional Comment #6 From Daniel Rall 2003-08-24 17:05 [reply] ------- 
FYI, Scarab <http://scarab.tigris.org/> contains an example of this.
---- bugzilla #20999 excerpt to here ----
   http://issues.apache.org/bugzilla/show_bug.cgi?id=20999

I grep-ed the scarab source, only to find how not to log a message on
null-setting.  (o.t.s.util.ReferenceInsertionFilter)  Can anyone give
me a clue how to #set to null using the EventCartridge?

TIA.

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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


Re: RFE: null support

Posted by Will Glass-Husain <wg...@forio.com>.
Hi,

Just my quick two cents.  I've been using JSP/JSTL a lot in the last year, 
and it's made life much easier by treating null/empty string equivalent, at 
least when checking to see if something is empty with the "empty" function. 
Also some of the databases do this (Oracle in particular).  I sort of think 
this makes sense.

But regardless of the string/null debate, it's definitely confusing to users 
when Velocity silently dies on a null.  Just one of many issues we seem to 
be stuck with.

WILL


----- Original Message ----- 
From: "Nathan Bubna" <nb...@gmail.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Saturday, December 04, 2004 11:59 AM
Subject: Re: RFE: null support


> On Sun, 05 Dec 2004 04:27:57 +0900, Urban Peter <ur...@jaist.ac.jp> wrote:
>> On Sat, 2004-12-04 at 10:17 -0800, Nathan Bubna wrote:
>>
>>
>> > On Sun, 5 Dec 2004 00:11:43 +0900, Shinobu Kawai
>> > <sh...@gmail.com> wrote:
>> > > Hi all,
>> > >
>> > > If Velocity were to support null, how would you expect it to behave?
>> > >
>> > > 1. The word "null" should be treated as null in Velocity specific 
>> > > content.
>> >
>> > -0  i'm not totally against it, but i'm instinctively uncomfortable
>> > with using this programming concept in a template language.
>> > personally, i've always felt in a display-oriented language, null and
>> > the empty string should be totally equivalent.  but that is already
>> > not the case, so i can't really be -1 on this.
>>
>> Well, Velocity is not just a display-oriented language, but a display-
>> oriented language that interacts with Java... that's why it's so useful.
>> And Java distinguishes null from the empty string.
>
> Java, being strongly-typed, distinguishes many things that VTL tries
> not to distinguish (e.g. see what #foreach accepts).
>
>> > > 2. The "set" directive should accept null value as the RHS.
>>
>> Oh yes, please... you mean, we could stop writing
>>
>> #set ($a = false)
>> #set ($a = $obj.method())
>>
>> ?
>
> yep, that's what it would mean.  wouldn't it be great!  of course,
> we've had talks about all this before, and i think patches have even
> been made.  i'm not getting my hopes up yet.
>
> -nathan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 


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


Re: RFE: null support

Posted by Nathan Bubna <nb...@gmail.com>.
On Sun, 05 Dec 2004 04:27:57 +0900, Urban Peter <ur...@jaist.ac.jp> wrote:
> On Sat, 2004-12-04 at 10:17 -0800, Nathan Bubna wrote:
> 
> 
> > On Sun, 5 Dec 2004 00:11:43 +0900, Shinobu Kawai
> > <sh...@gmail.com> wrote:
> > > Hi all,
> > >
> > > If Velocity were to support null, how would you expect it to behave?
> > >
> > > 1. The word "null" should be treated as null in Velocity specific content.
> >
> > -0  i'm not totally against it, but i'm instinctively uncomfortable
> > with using this programming concept in a template language.
> > personally, i've always felt in a display-oriented language, null and
> > the empty string should be totally equivalent.  but that is already
> > not the case, so i can't really be -1 on this.
> 
> Well, Velocity is not just a display-oriented language, but a display-
> oriented language that interacts with Java... that's why it's so useful.
> And Java distinguishes null from the empty string.

Java, being strongly-typed, distinguishes many things that VTL tries
not to distinguish (e.g. see what #foreach accepts).

> > > 2. The "set" directive should accept null value as the RHS.
> 
> Oh yes, please... you mean, we could stop writing
> 
> #set ($a = false)
> #set ($a = $obj.method())
> 
> ?

yep, that's what it would mean.  wouldn't it be great!  of course,
we've had talks about all this before, and i think patches have even
been made.  i'm not getting my hopes up yet.

-nathan

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


Re: RFE: null support

Posted by Urban Peter <ur...@jaist.ac.jp>.
On Sat, 2004-12-04 at 10:17 -0800, Nathan Bubna wrote:
> On Sun, 5 Dec 2004 00:11:43 +0900, Shinobu Kawai
> <sh...@gmail.com> wrote:
> > Hi all,
> > 
> > If Velocity were to support null, how would you expect it to behave?
> >
> > 1. The word "null" should be treated as null in Velocity specific content.
> 
> -0  i'm not totally against it, but i'm instinctively uncomfortable
> with using this programming concept in a template language. 
> personally, i've always felt in a display-oriented language, null and
> the empty string should be totally equivalent.  but that is already
> not the case, so i can't really be -1 on this.

Well, Velocity is not just a display-oriented language, but a display-
oriented language that interacts with Java... that's why it's so useful.
And Java distinguishes null from the empty string.

> > 2. The "set" directive should accept null value as the RHS.

Oh yes, please... you mean, we could stop writing

#set ($a = false)
#set ($a = $obj.method())

?

Ciao,

Peter

-- 
URBAN Peter, Ph.D.
Grad. School of Information Science   email:  urban@jaist.ac.jp
Japan Advanced Institute              web:    www.jaist.ac.jp/~urban
  of Science and Technology (JAIST)   phone:  +81 (761) 51 1254
1-1 Asahidai, Tatsunokuchi, Nomi      fax:    +81 (761) 51 1149
Ishikawa 923-1292, Japan              office: I-61



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


Re: RFE: null support

Posted by Mike Kienenberger <mk...@alaska.net>.
Nathan Bubna <nb...@gmail.com> wrote:
> -0  i'm not totally against it, but i'm instinctively uncomfortable
> with using this programming concept in a template language. 
> personally, i've always felt in a display-oriented language, null and
> the empty string should be totally equivalent.  but that is already
> not the case, so i can't really be -1 on this.

Tim Colson <tc...@cisco.com> wrote:
> +1, although, like Nathan... I'm also a little nervous with a View layer
> 'knowing' about nulls. But I think it's a necessary evil, and already 
there
> with lots of workarounds. So I'm in favor of making it clearer. 
> ... I am not sure I want to tell my template folks about "null" ;-)

If you're already treating null as "", none of this stuff should break 
backwards-compatibility.
And there's no requirement to tell your templaters about null unless you're 
actually using it.

Null's more than a programming concept.  Translate Strings into books:   If 
I have no book, that's different from having a book with no writing in it.  
>>From the point of view of "knowledge", they're the same, but if you're 
counting books, they aren't.

I still see absolutely no way a person can justify having #set and #foreach 
ignore nulls.  It doesn't "work" if you consider null to be functionally the 
same as an empty string.  It provides NO utility.  If you use it in a 
#foreach loop, null means repeat the last operation!  I could almost buy it 
if it set the value to "" rather than leaving it unchanged.

It reminds me of the old apple II disk copy protections.  The hardware 
couldn't read more than a certain number of consequetive zero bytes 
accurately, and if such a condition appeared on your disk, you had no way of 
knowing how many zeros you read.


Tim Colson <tc...@cisco.com> wrote:
> What would happen for these cases?
> #if ($!foo == null) 
> 
> Would position have any effect (i.e. like in Java to avoid NPE's) ?
> #if (null == $not_in_context)
> #if (null == $!not_in_context)

Why would these make any difference?

$! means suppress output if null.  There's no output inside a directive 
expression.

I'd expect it'd work the same way as the following

#if ("x" == $!not_in_context)

-Mike

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


Re: RFE: null support

Posted by Nathan Bubna <nb...@gmail.com>.
On Sun, 5 Dec 2004 00:11:43 +0900, Shinobu Kawai
<sh...@gmail.com> wrote:
> Hi all,
> 
> If Velocity were to support null, how would you expect it to behave?
>
> 1. The word "null" should be treated as null in Velocity specific content.

-0  i'm not totally against it, but i'm instinctively uncomfortable
with using this programming concept in a template language. 
personally, i've always felt in a display-oriented language, null and
the empty string should be totally equivalent.  but that is already
not the case, so i can't really be -1 on this.

> 2. The "set" directive should accept null value as the RHS.

+1, but perhaps with a velocity.property that can toggle this in case
some hypothetical user requires backwards compatibility.

> 3. The "foreach" directive should set null when the element is null.
> Currently, it preserves the last element.

+1, same as #2

> 4. The "if" directive should be able to compare references with null.

-0, same reasons as #1.

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


Re: RFE: null support

Posted by Shinobu Kawai <sh...@gmail.com>.
Thanks for all of your input, everyone!

> If Velocity were to support null, how would you expect it to behave?

I'll try to sum it up into a new Wiki page, under the "Architecture
Discussions & Debates" section.
   http://wiki.apache.org/jakarta-velocity/
## VelocityNullSupport, maybe?

I also want to put workarounds for the current version users.

I'm trying to figure out the EventCartridge way, but without success. 
In bugzilla #20999, Dan said:
---- bugzilla #20999 excerpt from here ----
------- Additional Comment #5 From Daniel Rall 2003-08-22 23:05 [reply] ------- 
This can already be accomplished via an EventCartridge.

------- Additional Comment #6 From Daniel Rall 2003-08-24 17:05 [reply] ------- 
FYI, Scarab <http://scarab.tigris.org/> contains an example of this.
---- bugzilla #20999 excerpt to here ----
   http://issues.apache.org/bugzilla/show_bug.cgi?id=20999

I grep-ed the scarab source, only to find how not to log a message on
null-setting.  (o.t.s.util.ReferenceInsertionFilter)  Can anyone give
me a clue how to #set to null using the EventCartridge?

TIA.

Best regards,
-- Shinobu Kawai

--
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


Re: RFE: null support

Posted by Shinobu Kawai <sh...@gmail.com>.
> 2. The "set" directive should accept null value as the RHS.
> 
> eg.
> Assuming that $bar wasn't in the Context,
> #set ($foo = $bar)
> #set ($foo = null)
> should both remove "foo" from the Context.

Actually, there's more to the "set" directive than just toggling the
Context.  #set can also set values to properties.

#set($map = {"foo" : "bar"})
#set($map.foo = null)

should set the value of "foo" of the Map "map" to null.

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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


RE: null support

Posted by Tim Colson <tc...@cisco.com>.
> 1. The word "null" should be treated as null in Velocity 
> specific content.
+1, although, like Nathan... I'm also a little nervous with a View layer
'knowing' about nulls. But I think it's a necessary evil, and already there
with lots of workarounds. So I'm in favor of making it clearer. 

> 2. The "set" directive should accept null value as the RHS.
+1
> 3. The "foreach" directive should set null when the element is null. 
> Currently, it preserves the last element.
+1 -- the current behavior always seems to 'surprise' people, myself
included. I'd rather see nulls behave more like people expect.

> 4. The "if" directive should be able to compare references with null.
> #if ($foo == null)
+0 ... I am not sure I want to tell my template folks about "null" ;-)

What would happen for these cases?
#if ($!foo == null) 

Would position have any effect (i.e. like in Java to avoid NPE's) ?
#if (null == $not_in_context)
#if (null == $!not_in_context)


Cheers,
Tim
P.S. Shinobu -- nice job on the summarization of the issue and proposed
changes! 


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


Re: RFE: null support

Posted by Mike Kienenberger <mk...@alaska.net>.
Shinobu Kawai <sh...@gmail.com> wrote:
> If Velocity were to support null, how would you expect it to behave?
> 
> 1. The word "null" should be treated as null in Velocity specific content.
> 2. The "set" directive should accept null value as the RHS.
> 3. The "foreach" directive should set null when the element is null. 
> 4. The "if" directive should be able to compare references with null.


Sounds perfect to me!

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