You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by sabatier <fl...@tcd.ie> on 2007/07/26 09:19:36 UTC

ArrayList and #foreach

Hi I have an ArrayList of checkbox values from a form. The ArrayList is
populated in the following way in a java servlet (where 'rw' is the
ArrayList):

if ( item.isFormField() && item.getFieldName().equalsIgnoreCase("rw")) {
                rw.add(item.getString());
            }

.
.
.
context.put("rw", rw);

I want to put these values into a velocity/xml template using the #foreach
loop.
eg. 

#foreach( $item in $rw)
         $item
#end

This isn't working however. Could someone tell me where I'm going wrong?
Any help would be appreciated.

-- 
View this message in context: http://www.nabble.com/ArrayList-and--foreach-tf4149754.html#a11805367
Sent from the Velocity - User mailing list archive at Nabble.com.


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


Re: ArrayList and #foreach

Posted by Claude Brisson <cl...@renegat.net>.
Le jeudi 26 juillet 2007 à 00:19 -0700, sabatier a écrit :
> Hi I have an ArrayList of checkbox values from a form. The ArrayList is
> populated in the following way in a java servlet (where 'rw' is the
> ArrayList):
> 
> if ( item.isFormField() && item.getFieldName().equalsIgnoreCase("rw")) {
>                 rw.add(item.getString());
>             }
> 
> .
> .
> .
> context.put("rw", rw);
> 
> I want to put these values into a velocity/xml template using the #foreach
> loop.
> eg. 
> 
> #foreach( $item in $rw)
>          $item
> #end
> 
> This isn't working however. Could someone tell me where I'm going wrong?
> Any help would be appreciated.

Can you tell us more? What is happening exactly?

You can print usefull debugging informations in VTL, like:

the arraylist: $rw ## should display sthing like "{ item1 item2 }"

its length: $rw.size()

#foreach($item in $rw)
	found class $item.class.name
#end

etc...


  Claude




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