Sidharth Sidharth - 2 months ago 10
Groovy Question

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>



Answer

Controller:

def list(){
 Student stud = new Student()
 def listStudents = stud.executeQuery("from Student")
 def displayStudentList = []
 listStudents.each{ lisStud->
  println "email = ${lisStud.email}"
  displayStudentList += it 
 }
 [displayStudentList : displayStudentList]
}

Views:

list.gsp

<g:each in="${displayStudentList}" var="lisStud">
  <td>${lisStud.email}</td>
</g:each>
Comments