anon
anon

Reputation:

Two Domain Objects in One View

Can two domain objects show on the same page, when the list method is called, for example?

http://APP_NAME/foo/list


def list = {
    if(!params.max) params.max = 10
    [ fooList: Foo.list( params ) ]
    [ barList: Bar.list( params ) ]  // Only the last one is returned.

}

On the view page, both tables would be displayed on the page.

 <g:each in="${fooList}" status="i" var="foo"> ... </g:each>
 <g:each in="${barList}" status="i" var="bar">  </g:each>

Upvotes: 3

Views: 678

Answers (2)

billjamesdev
billjamesdev

Reputation: 14642

Pretty sure you can return multiple things in that last line:

[ fooList: Foo.list( params ), barList: Bar.list( params ) ]

Upvotes: 7

Ruben
Ruben

Reputation: 9120

The comma in the accepted answer is correct, you can remove the // line.

Upvotes: 0

Related Questions