You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Thomas Veith <th...@web.de> on 2003/07/27 21:26:13 UTC

Problem with #set ( $val = $obj.someFunc() ) when someFunc() returns null..

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I have following problem:

#set ( $spieler = $user.AktKader.getMittelfeld(0) )
#if ( $spieler )
	<table>...</table>
#else
	<table>...</table>
#end
...
#set ( $spieler = $user.AktKader.getMittelfeld(1) )
#if ( $spieler )
	<table>...</table>
#else
	<table>...</table>
#end

Now, if getMittelfeld(0)  returns an Object, and getMittelfeld(1) returns 
null, $spieler keeps the value from getMittelfeld(0) instead of becoming 
null.

Therefore the table is full of the same entries :-(

Have I done anything wrong? Is this a bug? A feature? 

Any help would be most appreciated.

Best regards,
Thomas Veith

p..s: @Nathan: thanks for your advice, now that servlet works as expected :)

- -- 
Yes, but every time I try to see things your way, I get a headache.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE/JCdZEr7MtQIJYhsRAkVRAJ9Fsp0R/nn24lPub8Wor8wUteNfqgCdFPrq
RVBbdFUn9isJKK6B03tRWe8=
=jpKD
-----END PGP SIGNATURE-----


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


RTFM, but.. was Re: Problem with #set ( $val = $obj.someFunc() )..

Posted by Thomas Veith <th...@web.de>.
Hi,

Okay, next time i will read the manuals better BEFORE posting to the ML.. :-)

But WHY does velocity don't null a value in context when the RHS of the #set 
is null?

This can't be a technically reason; you don't need to remove it from context 
but only context.put("val",null) instead.. so why do you haven choosen to 
work this way?

Best regards,
Thomas




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


Re: Problem with #set ( $val = $obj.someFunc() ) when someFunc() returns null..

Posted by Nathan Bubna <na...@esha.com>.
Thomas Veith said:
...
> Good idea. I have patched the current CVS-Version that it looks for
> a boolean property "directive.set.rhs.null.allowed". If this is explicit set
> to true, then the value in the context becomes null if the RHS is null. If
> not, the old behaviour of ignoring and logging applies.
>
> Attached is a cvs-diff which seems to work so far...

hey, cool!  would you post this in Bugzilla?  it looks like the issue is
already brought up in bugs #17060 and #20999.   i suggest attaching it to one
(or both? i dunno, one should probably be marked as a duplicate of the other)
of them and adding the keyword PatchAvailable.

anyway, putting it in bugzilla makes sure it doesn't get lost or forgotten.

Nathan Bubna
nathan@esha.com


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


Re: Problem with #set ( $val = $obj.someFunc() ) when someFunc() returns null..

Posted by Thomas Veith <th...@web.de>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Sonntag, 27. Juli 2003 22:29 schrieb Nathan Bubna:
> Thomas Veith said:
>
> > Have I done anything wrong? Is this a bug? A feature?
>
> nope you've done nothing wrong.  it is the "intended" behavior.  some
> people call it a bug, some call it a feature.  most agree that a future
> version should allow the behavior of null set statements to be configured
> via the velocity.properties, but so far, no one has implemented such a
> change.  

Good idea. I have patched the current CVS-Version that it looks for a boolean 
property "directive.set.rhs.null.allowed". If this is explicit set to true, 
then the value in the context becomes null if the RHS is null. If not, the 
old behaviour of ignoring and logging applies.

Attached is a cvs-diff which seems to work so far...

Best regards,
Thomas

- -- 
"I was gratified to be able to answer promptly, and I did.  I said I
didn't know."
		-- Mark Twain
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE/JEzlEr7MtQIJYhsRAj+UAJ0cdZdhQHxDoVF4dyLJ2blkJgx76QCggI9A
vyKh1IVfyZDCDCMCwT85s1Q=
=Y6Py
-----END PGP SIGNATURE-----

Re: Problem with #set ( $val = $obj.someFunc() ) when someFunc() returns null..

Posted by Nathan Bubna <na...@esha.com>.
Thomas Veith said:
...
> Have I done anything wrong? Is this a bug? A feature?
...

nope you've done nothing wrong.  it is the "intended" behavior.  some people
call it a bug, some call it a feature.  most agree that a future version
should allow the behavior of null set statements to be configured via the
velocity.properties, but so far, no one has implemented such a change.  in the
meantime, here's what i would do:

#set( $foo = $tool.getNeverNull() )
...
#set( $foo = "" )
#set( $foo = $tool.getPossibleNull() )
#if( "$!foo" == "" )
foo wasn't null!
#else
foo was null.
#end

yes, it's a bit hackish, but if you really can't guarantee that your
tools/model will always return the "proper" data, this will at least work as
expected.

Nathan Bubna
nathan@esha.com


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