Sunday, April 13, 2008

Controller & Templates in Grails

The common way of using template in Grails is within a GSP page where a page is designed to be composed of different components, each component defined in a template.

In a GSP, one would write

<g:render template="orderDetailsTemplate"
mode:[orderItems:orderItems]/>


The other way however is to decide about the use of a template directly from a Controller:


class OrderController {
def list = {
def orderItems = OrderItem.list( params )
render(temlate:"orderDetailsTemplate"
model:[ orderItems: orderItems])
}
}


A good use-case of using the second way is when an ajax call is made from a GSP page and the result should update a div.

No comments: