PassionateProgrammer
PassionateProgrammer

Reputation: 874

Rendering an array of objects in the form of table rows in gsp

I have a controller action named "save" which is called when a submitButton is pressed and the save action calls a java function and is getting an array of objects as result.Let A be the name of the collection and it is a collection of objects of class B.Now this A is passed as a model to a template named _C.gsp rendered by the action "save".Within _C.gsp,what is needed is to show three properties named name,id,street of each B object, inside the collection A, in a tabular format.What i tried is this:

Template:_C.gsp

<table cellpadding="0" cellspacing="0">
<thead>
    <tr>
        <th class="small"><g:message code="Name"/></th>
        <th class="medium"><g:message code="ID"/></th>
        <th class="tiny"><g:message code="STREET"/></th>
    </tr>
</thead>
<tbody>
    <g:each in="${A}" >
    <g:each in="${A.Name}" status="idx" var="nam" >
       <tr>
         <td>

                ${nam}

                 </td>
         <td>
                    //how can I show id here
                  </td>
                  <td>         
                           // how can I show street here
                  </td>
             </g:each>
         </g:each>
      </tbody>

     </table>

PLZ helppp...

Upvotes: 0

Views: 1657

Answers (1)

cawka
cawka

Reputation: 437

There is no need for a double iteration. It should work like this

<g:each in="${A}" var="B">
    <tr>
        <td>
            ${B.name}
        </td>
        <td>
            ${B.id}
        </td>
        <td>         
            ${B.street}
        </td>
    </tr>
</g:each>

Upvotes: 1

Related Questions