withFormat - correct usage?

8 views
Skip to first unread message

Toby Hobson

unread,
Feb 17, 2016, 10:56:28 AM2/17/16
to Grails Dev Discuss
Following the docs I tried using this code block:

def products = Product.list()

withFormat {
    html productList: products
    json { render products as JSON }
}


A call to /product/list?format=json returns the JSON for the products but a call to /product/list?format=html renders the product/list view but the products are not passed in

I found this works though:

withFormat {
    html { [ products: products ] }
    ...
}


or

withFormat {
    html { new ModelAndView('list', [ products: products]) }
    ...
}


Am I missing something or do the docs need updating?
Reply all
Reply to author
Forward
0 new messages