velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Warner Onstine" <war...@warneronstine.com>
Subject Re: Treatment of null variables in Velocity
Date Sat, 14 Jul 2001 23:58:28 GMT
What you actually need to do is this:
$!record.last_name

So, if the last_name var is null it outputs an empty string. This is
discussed in:

http://jakarta.apache.org/velocity/user-guide.html

-warner

----- Original Message -----
From: "Jonathan Revusky" <jrevusky@terra.es>
To: <velocity-user@jakarta.apache.org>
Sent: Saturday, July 14, 2001 4:33 PM
Subject: Treatment of null variables in Velocity


> I have been playing with Velocity recently. I actually have a first pass
> of integrating velocity as an option in the Niggle web application
> framework (it currently supports freemarker and webmacro, but
> announcement on velocity forthcoming...). Anyway, I am rather dismayed
> about how velocity treats null variables. I frequently use a pattern
> where, in a form, I go:
>
> <INPUT TYPE="TEXT" NAME="last_name" VALUE="$record.last_name" SIZE="25">
>
> Or something like that. Where the $record is a wrapper variable around a
> database record in my framework. Anyway, if last_name is null, then it
> actually puts in the literal string "$record.last_name". I mean, that's
> terrible! I could see where that is good at a debugging level, but
> really.... I mean, otherwise, you need to make sure that you always
> replace this by the empty string. Quite literally, it seems like you
> need something like:
>
> #set ($last_name="")
> #if ($record.last_name) #set ($last_name = $record.last_name) #end
> <INPUT TYPE="TEXT" NAME="last_name" VALUE="$last_name" SIZE="25">
>
> This is awkward! Has there been any discussion of this?
>
> Cheers,
>
> Jonathan Revusky
> --
> available for Java/Delphi/Internet consulting
> If you want to...
> - make your .class files double-clickable with SmartJ
> - do Delphi/Java mixed programming with easy-to-use JNI wrapper classes
> - build robust web applications with the Niggle Application Framework
> then...
> check out the Revusky Hacks Page: http://revusky.com/hacks/
>


Mime
View raw message