How to get list items in Velocity by using the foreach loop to display as a table

advertisements

I have a list which i am getting from database.I have 6 elements in the list

 List<String> list=new ArrayList<String>();
 list.add("No Connection");
 list.add("sep 24 ,2009");
 list.add("no issues are there");
 list.add("dec 30,2012");
 list.add("no meter");
 list.add("april 12,2013");

map.put("list",list);

I am using Velocity template. In that i am using foreach loop to get the list items.I have to display in the table with two cells in the first cell three elements in the even indexes should display and in second cell odd indexes should display.How can do that.

#foreach($mylist in $list)
    <td>even indexed list elements in my list</td>
    <td align="center">odd indexed elements in the list.</td>
    #end

Update:

I tried like this but it doesn't work.Is this correct way of getting indexes in velocity.

#set ($counter = 0)
#foreach ($i in $descList)
    #set ($counter = $counter + 1)
    #if ( $couter % 2 == 0)
        <td>$descList[$i]</td>
        <td align="center"></td>
    #else
        <td></td>
        <td align="center">$descList[$i+1]</td>
    #end
#end

I am getting following error.

07:53:31,952 ERROR VelocityEngine:43 - Left side ($couter) of modulus operation has null value. Operation not possible. /emailtemplates/diis_nem_issues_email.vm [line 47, column 20]

07:53:31,953 ERROR VelocityEngine:43 - Left side ( 2 ) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. /emailtemplates/diis_nem_issues_email.vm [line 47, column 25]


I resolved this issue by using hashtable in my application instead of List in my application

#foreach( $key in $hashtab.keySet() )
 <tr><td>$key</td><td align="center">$hashtab.get($key)</td></tr>
#end

and in my java class i have like this

HashTable<String,Date> hashtab=new HashTable<String,Date>();
hashtab.put(key,value);

Thanks guys for your Ideas.