I’m attempting to call a method from a controller in my grails project that I can iterate over and display items in a list.
//Controller code
Class TicketController {
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
def ticketsByDate = {
return [tickets : Ticket.list(sort: 'dateCreated')]
}
...
GSP code
<div class="box-content">
<ul class="tickets">
<g:each var="ticket" in="${ticketsByDate}" controller="ticket">
<li>${ticket.id}</li>
</g:each>
I might be looking at this from the wrong perspective, but what I want to be able to do is to make multiple calls like this from a page that aggregates data from several different sources. These sources would most likely be controller methods that made calls to services.
Any advice?
Thanks in advance
Have a look at the docs of the each tag. It is used to iterates over an collection.
You have to pass this collection from your controller to the view.
For your example – put the following snippet into your
ticketsByDateview:If you want to iterate over different objects of data sources you have to aggregate the data within your controller and pass them to view: