newcomer

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

newcomer

Pietro Maggi
Hi,
I'm evaluating Grails for a quick project I'm starting right now, it
look very good and I'll probably push it at my current employer.

Groovy and Grails are impressive, but I have some hard time to figure
out how to do simple things  (and docs does not help).

I've two domain class in my test application, and I'd like to iterate
over all the object in one domain-class while inside the "other"
domain class.

(I'm sorry, english is not my language)

To make it a bit cleaner I'll use the book, author example of the docs:
How can I iterate (using a <g:each>) over all the books while in the
author view?

I've seen that is possible to call something like:
def results = Book.findAll()

I can put this in the controller, but I can I pass it to the view?

thanks
Pietro
Reply | Threaded
Open this post in threaded view
|

Re: newcomer

graemer
On 4/19/06, Pietro Maggi <[hidden email]> wrote:

> Hi,
> I'm evaluating Grails for a quick project I'm starting right now, it
> look very good and I'll probably push it at my current employer.
>
> Groovy and Grails are impressive, but I have some hard time to figure
> out how to do simple things  (and docs does not help).
>
> I've two domain class in my test application, and I'd like to iterate
> over all the object in one domain-class while inside the "other"
> domain class.
>
> (I'm sorry, english is not my language)
>
> To make it a bit cleaner I'll use the book, author example of the docs:
> How can I iterate (using a <g:each>) over all the books while in the
> author view?

from a view:

<g:each in="${Book.list()}">
    Title: ${it.title}
</g:each>

>
> I've seen that is possible to call something like:
> def results = Book.findAll()

From a controller return the books as a model (a map essentially) in
your action:

@Property listBooks = {
    return [books: Book.list() ]
}

Then iterative over them in your view:

<g:each in="${books}">
    Title: ${it.title}
</g:each>

Graeme
>
> I can put this in the controller, but I can I pass it to the view?
>
> thanks
> Pietro
>
Reply | Threaded
Open this post in threaded view
|

Re: newcomer

Pietro Maggi
Thanks Graeme,

2006/4/19, Graeme Rocher <[hidden email]>:

> On 4/19/06, Pietro Maggi <[hidden email]> wrote:
> > To make it a bit cleaner I'll use the book, author example of the docs:
> > How can I iterate (using a <g:each>) over all the books while in the
> > author view?
>
> from a view:
>
> <g:each in="${Book.list()}">
>     Title: ${it.title}
> </g:each>
>
This is exactly what I was looking for. THANKS

Ciao
Pietro