Grails pattern to reuse template on error

Posted by bsreekanth on Stack Overflow See other posts from Stack Overflow or by bsreekanth
Published on 2010-05-13T04:11:12Z Indexed on 2010/05/13 4:14 UTC
Read the original article Hit count: 306

Filed under:
|

Hello,
I have a gsp template, where the data for create view is passed through the controller.

def create = {
    def bookInstance = new Book()
bookInstance .properties = params
def map = getDefaultValues()
render(template: "create", model: [bookInstance : bookInstance ,
            title: map.title,
            somelist: somelist
            ....])

the gsp template

 <g:select optionKey="id" from="${somelist}" name="somelist.id" value="${bookInstance ?.somelist?.id}" noSelection="['null': '']"></g:select>

now, in the save method, if there is an error, it returns currently populated and validated instance (default scaffold implementation)

render(template: "create", model: [bookInstance : bookInstance ])

But the fields in the gsp (error page rendered from save action) is empty. I could see the reason as it looks the value in "${somelist}" , but it is not used in save method. Do i just need to check for null in the gsp and use whichever map is available, or any better method (passing all the map in the save method is not an option) ..
thanks in advance..

© Stack Overflow or respective owner

Related posts about grails

Related posts about gsp