You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Robert Koberg <ro...@koberg.com> on 2007/04/10 18:05:23 UTC
looping through lists with object arrays
Hi,
I was wondering if there is a new way to handle lists of object arrays.
E.g.
List<Object[]> objects = hibernateQuery.list();
/*
Where the list looks like:
Object[] obj = objects.get(0);
obj[0] = "foo";
obj[1] = "bar";
*/
etc...
and then in Velcoity, from what I have seen in the list archives, you
should do something like:
#foreach ($task in $declinedTasks)
#set ($taskDetailId = -1)
#set ($taskId = -1)
#foreach ($value in $task)
#if ($velocityCount == 1)
#set ($taskDetailId = $value)
#elseif ($velocityCount == 2)
#set ($taskId = $value)
#end
#end
##do stuff
#end
Is this still considered the best way to handle the above, or is there
something new in v1.5?
thanks,
-Rob
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: looping through lists with object arrays
Posted by Robert Koberg <ro...@koberg.com>.
Great, thanks.
I will probably just stick with pure VTL as I only need this twice in my
app. The v1.6 way sounds good and looks like it would be backwards
compatible.
best,
-Rob
On Tue, 10 Apr 2007 12:13:23 -0400, Nathan Bubna <nb...@gmail.com> wrote:
> On 4/10/07, Robert Koberg <ro...@koberg.com> wrote:
>> Hi,
>>
>> I was wondering if there is a new way to handle lists of object arrays.
>> E.g.
>>
>> List<Object[]> objects = hibernateQuery.list();
>> /*
>> Where the list looks like:
>>
>> Object[] obj = objects.get(0);
>> obj[0] = "foo";
>> obj[1] = "bar";
>> */
>>
>> etc...
>>
>> and then in Velcoity, from what I have seen in the list archives, you
>> should do something like:
>>
>> #foreach ($task in $declinedTasks)
>> #set ($taskDetailId = -1)
>> #set ($taskId = -1)
>> #foreach ($value in $task)
>> #if ($velocityCount == 1)
>> #set ($taskDetailId = $value)
>> #elseif ($velocityCount == 2)
>> #set ($taskId = $value)
>> #end
>> #end
>>
>> ##do stuff
>>
>> #end
>>
>> Is this still considered the best way to handle the above, or is there
>> something new in v1.5?
>
> in pure VTL with v1.5, yes, this is the best way. though in v1.6, you
> will be able to use $task.get(0) as i'm adding support for using
> common List methods on array references.
>
> in the meantime you could also consider using the ListTool from
> VelocityTools to do:
>
> $list.get($task, 0)
> and
> $list.get($task, 1)
>
> as the ListTool methods all work the same for both Lists and arrays.
>
>> thanks,
>> -Rob
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: looping through lists with object arrays
Posted by Nathan Bubna <nb...@gmail.com>.
On 4/10/07, Robert Koberg <ro...@koberg.com> wrote:
> Hi,
>
> I was wondering if there is a new way to handle lists of object arrays.
> E.g.
>
> List<Object[]> objects = hibernateQuery.list();
> /*
> Where the list looks like:
>
> Object[] obj = objects.get(0);
> obj[0] = "foo";
> obj[1] = "bar";
> */
>
> etc...
>
> and then in Velcoity, from what I have seen in the list archives, you
> should do something like:
>
> #foreach ($task in $declinedTasks)
> #set ($taskDetailId = -1)
> #set ($taskId = -1)
> #foreach ($value in $task)
> #if ($velocityCount == 1)
> #set ($taskDetailId = $value)
> #elseif ($velocityCount == 2)
> #set ($taskId = $value)
> #end
> #end
>
> ##do stuff
>
> #end
>
> Is this still considered the best way to handle the above, or is there
> something new in v1.5?
in pure VTL with v1.5, yes, this is the best way. though in v1.6, you
will be able to use $task.get(0) as i'm adding support for using
common List methods on array references.
in the meantime you could also consider using the ListTool from
VelocityTools to do:
$list.get($task, 0)
and
$list.get($task, 1)
as the ListTool methods all work the same for both Lists and arrays.
> thanks,
> -Rob
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org