velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <shinobu.ka...@gmail.com>
Subject Re: Problem handling null values
Date Thu, 04 Nov 2004 21:30:06 GMT
Hi Steve,

> I've got a table that outputs values from a 2 dimensional array of Strings;
> 
> <table>
>    #foreach ($Item in $Results)
>    <tr>
>        #foreach ($Field in $Item)
>            <td>$Field</td>
>        #end
>    </tr>
>    #end
> </table>
> 
> This works fine except when it comes across a null string in $Field.
> What it actually does is output the previous non-null value for $Field.
> 
> I assume this is a bug?
It's the way Velocity handles null:  Shun the whole process.  :(
So if you want to handle nulls in the array as null, you need to
null-ify the element at the end of the loop.

Using NullTool (http://wiki.apache.org/jakarta-velocity/NullTool):
  #foreach ($Field in $Item)
    <td>$Field</td>
    $null.setNull($ctx, "Field")
  #end

Or ViewNullTool (http://wiki.apache.org/jakarta-velocity/ViewNullTool):
  #foreach ($Field in $Item)
    <td>$Field</td>
    $null.setNull("Field")
  #end

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <shinobu.kawai@gmail.com>

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


Mime
View raw message