Search code examples
grailsgrails-orm

Getting a list of contacts from database and populating it to a view "list"


I am working on a grails application in which I want a list of contacts in a view named as "list". For this purpose, I have to use a custom view and a custom list action in controller... Below is my controller action code...

def list()
{
    def result =  Contact.findAll(sort: 'name')
    return [result: result]
}

Below is my list view code...

    <div class="span8 well">
    <div class="row-fluid">
       ${result}
    </div>
</div>

Now I want that when my list view is rendered, all the contacts and their info should be displayed in view.


Solution

  • For print your data on view you can try this syntax.

    <g:each in="${result}" var="instance">
    // put here your code according to your requirement. Like
    ${instance?.name}  // for getting all name in list.
    </g:each>