velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Seth Rosenblum" <srosenb...@wgen.net>
Subject RE: quiet reference doesn't throw exception
Date Mon, 07 Jul 2008 14:51:07 GMT
 
Actually, in that case the $isNull inside the if statement throws the
ParserConfigurationException.

Thanks though,
	Seth


-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: Saturday, July 05, 2008 11:46 AM
To: Velocity Users List
Subject: Re: quiet reference doesn't throw exception

Seth,

Seth Rosenblum wrote:
> I'm using the velocity engine with ParseErrorException throwing turned

> on because it greatly simplifies unit testing, as it just checks that 
> every value on the page has been filled in.  However, I'd like 
> velocity to not throw an exception when I pass it a quiet reference 
> e.g. $isNull should throw an exception, but $!isNull should just 
> resolve to being empty.  Is there a way to do this?

How about

#if($isNull)
(nothing)
#else
$!isNull
#end

This is quite verbose, but it will get the job done.

I've always been a proponent of something like ReferenceTools that would
allow you to do things like directly check for null and false (because
null == false in VTL) so you wouldn't have to use tricks like these to
get around this behavior. I've just been too lazy to do anything about
it so far ;)

-chris


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


Mime
View raw message