Search code examples
groovycontrollergsp

how to get values of list from controller to gsp


Have been trying to get values from different procedure, but no success.

CONTROLLER:

def list(){
    Student stud = new Student()
    def listStudents = stud.executeQuery("from Student")
    listStudents.each{ lisStud->

    println "email = ${lisStud.email}"
    render view:"/layouts/listOFstudents"
}

Table:

<table>
<tr>
    <g:each in="${lisStud}">
    <td>${lisStud.email}</td>


    </g:each>


Solution

  • class HelloController {
    def index() {
        def list = []
        list << new Person(firstName: 'John', lastName:'Doe', age:50)
        list << new Person(firstName: 'Jane', lastName:'Smith', age:45)
        list << new Person(firstName: 'Sam', lastName:'Robinson', age:47)
        [ list:list ]
    }
    

    }

    Just Don't Render the page to any other page then index