Search code examples
postgresqlgrailsgsp

Groovy-grails sql.rows in gsp table


Hi i want to display a list of the results from my database in a gsp.I have put the resultes in a g:each but the result is coming to a line and not in the table.

My service is this:

def listAction(){
        def sql = new Sql(dataSource)
        return sql.rows ("SELECT * FROM  mn")

my controller is this:

def list() {          
        [contacts : contactListService.listAction()]
    }

and gsp

<g:each in="${contacts}" var="contact" status="i">
                    <td>${contact.id}</td>
                    <td>${contact.name}</td>
                    <td><g:link action="edit" id="${contact.id}" class="btn btn-info" role="button">Edit</g:link>
                        <g:link action="delete" id="${contact.id}" button type="button" class="btn btn-danger">Delete</g:link></td>
                </g:each>

Solution

  • Each element should be wrapped in a new row.

    <g:each in="${contacts}" var="contact" status="i">
        <tr>
           <td>${contact.id}</td>
           <td>${contact.name}</td>
           <td><g:link action="edit" id="${contact.id}" class="btn btn-info" role="button">Edit</g:link>
               <g:link action="delete" id="${contact.id}" button type="button" class="btn btn-danger">Delete</g:link>
           </td>
        </tr>
    </g:each>