You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rich Garabedian <ri...@autorevenue.com> on 2006/03/05 16:18:19 UTC

List of Object Arrays

Greetings Users List.

Is there any way to loop through a List of Object Arrays in Velocity? In
other words:

Iterator i = myList.iterator();
            
while(i.hasNext())
{
    Object[] configArray = (Object[]) i.next();

    //Do something with object array
}



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


RE: List of Object Arrays

Posted by Rich Garabedian <ri...@autorevenue.com>.
Thanks again for the note. Nice that we have choices, I ended up doing this
based on Nathan's advise:

 

#foreach( $appt in $apptList ) 

   #foreach ($item in $appt)

 

      #if ($velocityCount == 1) 

         #set($APT = $item)

      #elseif ($velocityCount == 2) 

         #set($A = $item) 

      #elseif ($velocityCount == 3)

         #set($V = $item)

       #elseif ($velocityCount == 4) 

         #set($C = $item) 

       #end

 

    #end

 

    ## Do stuff with $A, $V, $C, or $APT

#end

 

  _____  

From: Bill Rishel [mailto:illusyn@gmail.com] 
Sent: Monday, March 06, 2006 7:11 PM
To: Velocity Users List; richg@autorevenue.com
Subject: Re: List of Object Arrays

 

OK, if you have to access the array items by index
number then use the ListTool:

Make sure you have the latest tools jar. Then put:

 <tool>
   <key>list</key>
   <scope>application</scope>
   <class>org.apache.velocity.tools.generic.ListTool</class>
 </tool>

into your toobox.xml

Then you can do:

#foreach ($array in $arrayList)
    #set($table1 = $list.get($array,0))
    #set($table2 = $list.get($array,1))
    #set($table3 = $list.get($array,2))

## etc.

#end

The "$list" is the handle to access the ListTool functionality.

Bill

On 3/6/06, Rich Garabedian <ri...@autorevenue.com> wrote:

Hey Bill.

Thanks so much for the note.

I don't think that code skeleton will for me because the objects in the
object array will be different. The List of object arrays is coming to me
from hibernate and in this particular scenario I'll have three different 
beans. What I really want to do is something like this:

#foreach ($array in $arrayList)
    #set($table1 = $array.get(0))
    #set($table2 = $array.get(1))
    #set($table3 = $array.get(2))

    ## Do stuff with $table1 
    ## Do stuff with $table2
    ## Do stuff with $table3
#end

But I couldn't get that to work

-----Original Message-----
From: Bill Rishel [mailto:illusyn@gmail.com  <ma...@gmail.com> ]
Sent: Monday, March 06, 2006 3:06 PM
To: Velocity Users List; richg@autorevenue.com
Subject: Re: List of Object Arrays

#foreach ($array in $arrayList)
    #foreach ($item in $array) 
       $item ## do something with  $item
    #end
#end


Bill


On 3/5/06, Rich Garabedian <ri...@autorevenue.com> wrote:
>
> Greetings Users List. 
>
> Is there any way to loop through a List of Object Arrays in Velocity? In
> other words:
>
> Iterator i = myList.iterator();
>
> while(i.hasNext())
> {
>     Object[] configArray = (Object[]) i.next();
>
>     //Do something with object array
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>



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

 


Re: List of Object Arrays

Posted by Bill Rishel <il...@gmail.com>.
OK, if you have to access the array items by index
number then use the ListTool:

Make sure you have the latest tools jar. Then put:

 <tool>
   <key>list</key>
   <scope>application</scope>
   <class>org.apache.velocity.tools.generic.ListTool</class>
 </tool>

into your toobox.xml

Then you can do:

#foreach ($array in $arrayList)
    #set($table1 = $list.get($array,0))
    #set($table2 = $list.get($array,1))
    #set($table3 = $list.get($array,2))

## etc.

#end

The "$list" is the handle to access the ListTool functionality.

Bill

On 3/6/06, Rich Garabedian <ri...@autorevenue.com> wrote:
>
> Hey Bill.
>
> Thanks so much for the note.
>
> I don't think that code skeleton will for me because the objects in the
> object array will be different. The List of object arrays is coming to me
> from hibernate and in this particular scenario I'll have three different
> beans. What I really want to do is something like this:
>
> #foreach ($array in $arrayList)
>     #set($table1 = $array.get(0))
>     #set($table2 = $array.get(1))
>     #set($table3 = $array.get(2))
>
>     ## Do stuff with $table1
>     ## Do stuff with $table2
>     ## Do stuff with $table3
> #end
>
> But I couldn't get that to work
>
> -----Original Message-----
> From: Bill Rishel [mailto:illusyn@gmail.com]
> Sent: Monday, March 06, 2006 3:06 PM
> To: Velocity Users List; richg@autorevenue.com
> Subject: Re: List of Object Arrays
>
> #foreach ($array in $arrayList)
>     #foreach ($item in $array)
>        $item ## do something with  $item
>     #end
> #end
>
>
> Bill
>
>
> On 3/5/06, Rich Garabedian <ri...@autorevenue.com> wrote:
> >
> > Greetings Users List.
> >
> > Is there any way to loop through a List of Object Arrays in Velocity? In
> > other words:
> >
> > Iterator i = myList.iterator();
> >
> > while(i.hasNext())
> > {
> >     Object[] configArray = (Object[]) i.next();
> >
> >     //Do something with object array
> > }
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

RE: List of Object Arrays

Posted by Rich Garabedian <ri...@autorevenue.com>.
Thanks, that worked perfectly!

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: Monday, March 06, 2006 3:55 PM
To: Velocity Users List; richg@autorevenue.com
Subject: Re: List of Object Arrays

#foreach ($array in $arrayList)
   #foreach ($item in $array)
      #if ($velocityCount == 1 )
        ## Do stuff with $table1
      #elseif ($velocityCount == 2 )
        ## Do stuff with $table2
      #elseif ($velocityCount == 3)
        ## Do stuff with $table 3
      #end
   #end
#end

On 3/6/06, Rich Garabedian <ri...@autorevenue.com> wrote:
> Hey Bill.
>
> Thanks so much for the note.
>
> I don't think that code skeleton will for me because the objects in the
> object array will be different. The List of object arrays is coming to me
> from hibernate and in this particular scenario I'll have three different
> beans. What I really want to do is something like this:
>
> #foreach ($array in $arrayList)
>     #set($table1 = $array.get(0))
>     #set($table2 = $array.get(1))
>     #set($table3 = $array.get(2))
>
>     ## Do stuff with $table1
>     ## Do stuff with $table2
>     ## Do stuff with $table3
> #end
>
> But I couldn't get that to work
>
> -----Original Message-----
> From: Bill Rishel [mailto:illusyn@gmail.com]
> Sent: Monday, March 06, 2006 3:06 PM
> To: Velocity Users List; richg@autorevenue.com
> Subject: Re: List of Object Arrays
>
> #foreach ($array in $arrayList)
>     #foreach ($item in $array)
>        $item ## do something with  $item
>     #end
> #end
>
>
> Bill
>
>
> On 3/5/06, Rich Garabedian <ri...@autorevenue.com> wrote:
> >
> > Greetings Users List.
> >
> > Is there any way to loop through a List of Object Arrays in Velocity? In
> > other words:
> >
> > Iterator i = myList.iterator();
> >
> > while(i.hasNext())
> > {
> >     Object[] configArray = (Object[]) i.next();
> >
> >     //Do something with object array
> > }
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>




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


Re: List of Object Arrays

Posted by Nathan Bubna <nb...@gmail.com>.
#foreach ($array in $arrayList)
   #foreach ($item in $array)
      #if ($velocityCount == 1 )
        ## Do stuff with $table1
      #elseif ($velocityCount == 2 )
        ## Do stuff with $table2
      #elseif ($velocityCount == 3)
        ## Do stuff with $table 3
      #end
   #end
#end

On 3/6/06, Rich Garabedian <ri...@autorevenue.com> wrote:
> Hey Bill.
>
> Thanks so much for the note.
>
> I don't think that code skeleton will for me because the objects in the
> object array will be different. The List of object arrays is coming to me
> from hibernate and in this particular scenario I'll have three different
> beans. What I really want to do is something like this:
>
> #foreach ($array in $arrayList)
>     #set($table1 = $array.get(0))
>     #set($table2 = $array.get(1))
>     #set($table3 = $array.get(2))
>
>     ## Do stuff with $table1
>     ## Do stuff with $table2
>     ## Do stuff with $table3
> #end
>
> But I couldn't get that to work
>
> -----Original Message-----
> From: Bill Rishel [mailto:illusyn@gmail.com]
> Sent: Monday, March 06, 2006 3:06 PM
> To: Velocity Users List; richg@autorevenue.com
> Subject: Re: List of Object Arrays
>
> #foreach ($array in $arrayList)
>     #foreach ($item in $array)
>        $item ## do something with  $item
>     #end
> #end
>
>
> Bill
>
>
> On 3/5/06, Rich Garabedian <ri...@autorevenue.com> wrote:
> >
> > Greetings Users List.
> >
> > Is there any way to loop through a List of Object Arrays in Velocity? In
> > other words:
> >
> > Iterator i = myList.iterator();
> >
> > while(i.hasNext())
> > {
> >     Object[] configArray = (Object[]) i.next();
> >
> >     //Do something with object array
> > }
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


RE: List of Object Arrays

Posted by Rich Garabedian <ri...@autorevenue.com>.
Hey Bill.

Thanks so much for the note.

I don't think that code skeleton will for me because the objects in the
object array will be different. The List of object arrays is coming to me
from hibernate and in this particular scenario I'll have three different
beans. What I really want to do is something like this:

#foreach ($array in $arrayList)
    #set($table1 = $array.get(0))
    #set($table2 = $array.get(1))
    #set($table3 = $array.get(2))

    ## Do stuff with $table1
    ## Do stuff with $table2
    ## Do stuff with $table3
#end

But I couldn't get that to work

-----Original Message-----
From: Bill Rishel [mailto:illusyn@gmail.com] 
Sent: Monday, March 06, 2006 3:06 PM
To: Velocity Users List; richg@autorevenue.com
Subject: Re: List of Object Arrays

#foreach ($array in $arrayList)
    #foreach ($item in $array)
       $item ## do something with  $item
    #end
#end


Bill


On 3/5/06, Rich Garabedian <ri...@autorevenue.com> wrote:
>
> Greetings Users List.
>
> Is there any way to loop through a List of Object Arrays in Velocity? In
> other words:
>
> Iterator i = myList.iterator();
>
> while(i.hasNext())
> {
>     Object[] configArray = (Object[]) i.next();
>
>     //Do something with object array
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>



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


Re: List of Object Arrays

Posted by Bill Rishel <il...@gmail.com>.
#foreach ($array in $arrayList)
    #foreach ($item in $array)
       $item ## do something with  $item
    #end
#end


Bill


On 3/5/06, Rich Garabedian <ri...@autorevenue.com> wrote:
>
> Greetings Users List.
>
> Is there any way to loop through a List of Object Arrays in Velocity? In
> other words:
>
> Iterator i = myList.iterator();
>
> while(i.hasNext())
> {
>     Object[] configArray = (Object[]) i.next();
>
>     //Do something with object array
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>