You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Daniel Brownell <db...@htaconsulting.com> on 2005/09/30 00:48:46 UTC
Map.get(missingKey) doesnt return null.
Hi there,
Thanks for the help on the Map of maps question. This question is
related.
Velocity is giving me values when I should be getting null.
Here is the code:
#foreach ($student in students)
#set($storedMap = $storedTimes.get($student.getID()))
$student.getID() $storedMap <br>
#end
In the output below, 6 of the students are'nt actually mapped in
$storedMap.
Only the first of the students with sh=10, sh=1 or sh=6 are actually in
my HashMap. (ie. 492,493,496,497 are using 491's value.)
For some reason, the value of $storedMap is not updated to be null, as
it should, and I get stragglers copying values that aren't theirs. My
check for null is useless because Velocity is not behaving.
581502 {sh=7, eh=7, sa=PM, ea=PM, sm=30, em=00}
581503 {sh=8, eh=7, sa=PM, ea=PM, sm=30, em=00}
581504 {sh=9, eh=7, sa=PM, ea=PM, sm=30, em=00}
581491 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
581492 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
581493 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
581496 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
581497 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
581505 {sh=1, eh=6, sa=AM, ea=PM, sm=30, em=15}
581506 {sh=1, eh=6, sa=AM, ea=PM, sm=30, em=15}
581507 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
581508 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
581495 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
Thanks
Dan
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Map.get(missingKey) doesnt return null.
Posted by Jonathan Revusky <re...@wanadoo.es>.
Christoph Reck wrote:
> Hi,
>
> Daniel Brownell wrote:
>
>> Hi there,
>>
>> Thanks for the help on the Map of maps question. This question is
>> related. Velocity is giving me values when I should be getting null.
>
>
> that is the current standard behaviour of #set, where
> it won't change the value when trying to set a null.
> In the upcomging Vel release 1.5 there will be a flag
> to switch this odd behaviour off!
IOW, the buggy behavior will still be standard, but if you are bitten by
this bug, you can optionally (assuming you know about it) turn on the
bug fix via a flag.
Isn't that a rather odd approach to things?
Jonathan Revusky
--
FreeMarker project, http://freemarker.org/
>
> See more in the mailing lists (search for "null") and
> look at: http://issues.apache.org/jira/browse/VELOCITY-186
>
> The current workaround is to change the value before
> the next loop iteration, see below a possible solution:
>
>>
>> Here is the code:
>>
>> #foreach ($student in students)
>> #set($storedMap = $storedTimes.get($student.getID()))
>> $student.getID() $storedMap <br>
>
> #set($storedMap = "")
>
>> #end
>>
>> In the output below, 6 of the students are'nt actually mapped in
>> $storedMap.
>> Only the first of the students with sh=10, sh=1 or sh=6 are actually in
>> my HashMap. (ie. 492,493,496,497 are using 491's value.)
>>
>> For some reason, the value of $storedMap is not updated to be null, as
>> it should, and I get stragglers copying values that aren't theirs. My
>> check for null is useless because Velocity is not behaving.
>>
>> 581502 {sh=7, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581503 {sh=8, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581504 {sh=9, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581491 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581492 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581493 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581496 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581497 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
>> 581505 {sh=1, eh=6, sa=AM, ea=PM, sm=30, em=15}
>> 581506 {sh=1, eh=6, sa=AM, ea=PM, sm=30, em=15}
>> 581507 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
>> 581508 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
>> 581495 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
>>
>> Thanks
>> Dan
>>
>
> :) Christoph
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Map.get(missingKey) doesnt return null.
Posted by Christoph Reck <ap...@recks.org>.
Hi,
Daniel Brownell wrote:
> Hi there,
>
> Thanks for the help on the Map of maps question. This question is
> related.
> Velocity is giving me values when I should be getting null.
that is the current standard behaviour of #set, where
it won't change the value when trying to set a null.
In the upcomging Vel release 1.5 there will be a flag
to switch this odd behaviour off!
See more in the mailing lists (search for "null") and
look at: http://issues.apache.org/jira/browse/VELOCITY-186
The current workaround is to change the value before
the next loop iteration, see below a possible solution:
>
> Here is the code:
>
> #foreach ($student in students)
> #set($storedMap = $storedTimes.get($student.getID()))
> $student.getID() $storedMap <br>
#set($storedMap = "")
> #end
>
> In the output below, 6 of the students are'nt actually mapped in
> $storedMap.
> Only the first of the students with sh=10, sh=1 or sh=6 are actually in
> my HashMap. (ie. 492,493,496,497 are using 491's value.)
>
> For some reason, the value of $storedMap is not updated to be null, as
> it should, and I get stragglers copying values that aren't theirs. My
> check for null is useless because Velocity is not behaving.
>
> 581502 {sh=7, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581503 {sh=8, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581504 {sh=9, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581491 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581492 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581493 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581496 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581497 {sh=10, eh=7, sa=PM, ea=PM, sm=30, em=00}
> 581505 {sh=1, eh=6, sa=AM, ea=PM, sm=30, em=15}
> 581506 {sh=1, eh=6, sa=AM, ea=PM, sm=30, em=15}
> 581507 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
> 581508 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
> 581495 {sh=6, eh=6, sa=AM, ea=PM, sm=30, em=30}
>
> Thanks
> Dan
>
:) Christoph
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org