withFormat - correct usage?

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

withFormat - correct usage?

Toby Hobson
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 ] }


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

Am I missing something or do the docs need updating?

You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/a901bc70-d2b2-4901-8cd4-aa5db3e8f027%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.