You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Qin Ding <qd...@csc.com> on 2003/09/25 16:47:47 UTC

How to handle the nested Loop

I have in velocityContext a Hashtable.  The key is String type and value is
a ArrayList.
The arraylist holds number of java beans.  The each bean has a method
getFieldValues(), which returns an array
String[ ].  Now I try to print out each String value in the String[ ]
array.  I tested in java code to print out the value in the array; but in
my velocity template, I can't print anything.  I don't know why.  I don't
even know if this is the correct way of doing these nested looping.

#foreach( $key in $OFFENDIGN_ROWS.keySet() )
---------------> get key
    #set($upperKey = "${key.toUpperCase()}")
    <a class="large" name="${key}" id="${key}">${upperKey}</a>

    TABLE border="1" width="100%" cellspacing="0">
      #foreach( $field in $BEAN_FIELD_NAMES )
      <TH class="highlight">$field.Property</TH>
-----------------> This is ok
      #end

      #foreach( $rows in $OFFENDIGN_ROWS.get($key) )
-----------------> get the arrayList associated with key
      #foreach ($row in $rows)
------------------> get bean in the list

      #set($fieldValues = $row.getFieldValues)
------------------>  get the String[ ] array of the bean
      <TR>
      #foreach( $fieldValue in $fieldValues )
-------------------> get the String value from the array
        <TD> $fieldValue </TD>
--------------------> display nothing
      #end
      </TR>

      #end
      #end
    </TABLE>
    </p>
    #end

Did I do something wrong? Thank you.

Qin


----------------------------------------------------------------------------------------

This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit written
agreement or government initiative expressly permitting the use of e-mail
for such purpose.
----------------------------------------------------------------------------------------





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


Re: How to handle the nested Loop

Posted by Daniel Graham <da...@gr8.tv>.
Use either $row.getFieldValues() or $row.FieldValues

(Note parenthesis).

DG

Qin Ding wrote:

> I have in velocityContext a Hashtable.  The key is String type and value is
> a ArrayList.
> The arraylist holds number of java beans.  The each bean has a method
> getFieldValues(), which returns an array
> String[ ].  Now I try to print out each String value in the String[ ]
> array.  I tested in java code to print out the value in the array; but in
> my velocity template, I can't print anything.  I don't know why.  I don't
> even know if this is the correct way of doing these nested looping.
> 
> #foreach( $key in $OFFENDIGN_ROWS.keySet() )
> ---------------> get key
>     #set($upperKey = "${key.toUpperCase()}")
>     <a class="large" name="${key}" id="${key}">${upperKey}</a>
> 
>     TABLE border="1" width="100%" cellspacing="0">
>       #foreach( $field in $BEAN_FIELD_NAMES )
>       <TH class="highlight">$field.Property</TH>
> -----------------> This is ok
>       #end
> 
>       #foreach( $rows in $OFFENDIGN_ROWS.get($key) )
> -----------------> get the arrayList associated with key
>       #foreach ($row in $rows)
> ------------------> get bean in the list
> 
>       #set($fieldValues = $row.getFieldValues)
> ------------------>  get the String[ ] array of the bean
>       <TR>
>       #foreach( $fieldValue in $fieldValues )
> -------------------> get the String value from the array
>         <TD> $fieldValue </TD>
> --------------------> display nothing
>       #end
>       </TR>
> 
>       #end
>       #end
>     </TABLE>
>     </p>
>     #end
> 
> Did I do something wrong? Thank you.
> 
> Qin
> 
> 
> ----------------------------------------------------------------------------------------
> 
> This is a PRIVATE message. If you are not the intended recipient, please
> delete without copying and kindly advise us by e-mail of the mistake in
> delivery. NOTE: Regardless of content, this e-mail shall not operate to
> bind CSC to any order or other contract unless pursuant to explicit written
> agreement or government initiative expressly permitting the use of e-mail
> for such purpose.
> ----------------------------------------------------------------------------------------
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 

-- 
Dr Daniel Graham
Product Strategy Manager
Video and Image Coding Specialists
daniel.graham@videocoding.com
http://www.videocoding.com
Tel : [+44|0] 870 241 4618


Re: How to handle the nested Loop

Posted by Daniel Graham <da...@gr8.tv>.
Use either $row.getFieldValues() or $row.FieldValues

(Note parenthesis).

DG

Qin Ding wrote:

> I have in velocityContext a Hashtable.  The key is String type and value is
> a ArrayList.
> The arraylist holds number of java beans.  The each bean has a method
> getFieldValues(), which returns an array
> String[ ].  Now I try to print out each String value in the String[ ]
> array.  I tested in java code to print out the value in the array; but in
> my velocity template, I can't print anything.  I don't know why.  I don't
> even know if this is the correct way of doing these nested looping.
> 
> #foreach( $key in $OFFENDIGN_ROWS.keySet() )
> ---------------> get key
>     #set($upperKey = "${key.toUpperCase()}")
>     <a class="large" name="${key}" id="${key}">${upperKey}</a>
> 
>     TABLE border="1" width="100%" cellspacing="0">
>       #foreach( $field in $BEAN_FIELD_NAMES )
>       <TH class="highlight">$field.Property</TH>
> -----------------> This is ok
>       #end
> 
>       #foreach( $rows in $OFFENDIGN_ROWS.get($key) )
> -----------------> get the arrayList associated with key
>       #foreach ($row in $rows)
> ------------------> get bean in the list
> 
>       #set($fieldValues = $row.getFieldValues)
> ------------------>  get the String[ ] array of the bean
>       <TR>
>       #foreach( $fieldValue in $fieldValues )
> -------------------> get the String value from the array
>         <TD> $fieldValue </TD>
> --------------------> display nothing
>       #end
>       </TR>
> 
>       #end
>       #end
>     </TABLE>
>     </p>
>     #end
> 
> Did I do something wrong? Thank you.
> 
> Qin
> 
> 
> ----------------------------------------------------------------------------------------
> 
> This is a PRIVATE message. If you are not the intended recipient, please
> delete without copying and kindly advise us by e-mail of the mistake in
> delivery. NOTE: Regardless of content, this e-mail shall not operate to
> bind CSC to any order or other contract unless pursuant to explicit written
> agreement or government initiative expressly permitting the use of e-mail
> for such purpose.
> ----------------------------------------------------------------------------------------
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 

-- 
Dr Daniel Graham
Product Strategy Manager
Video and Image Coding Specialists
daniel.graham@videocoding.com
http://www.videocoding.com
Tel : [+44|0] 870 241 4618


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