small medium large xlarge

Back to: All Forums  Grails
Generic-user-small
17 Jul 2009, 19:39
Marc Hollins (5 posts)

Hi,

I am working through chapter 7 “Forum Messages and UI Tricks,” and was wondering about the usage of single quotes in the calls to the render() method.

Sometimes you use render(view:'create',model:[messageInstance:messageInstance]) other times its render(view:'create', model:['messageInstance':messageInstance])

Are the single quotes around ‘messageInstance’ optional, or is there a reason to use/omit them?

thanks, Marc

Dklein_tiny_pragsmall
24 Jul 2009, 23:13
Dave Klein (34 posts)

Hi Marc,

Sorry for the slow reply. I wish I could say that I was trying to show different options or something meaningful like that, but I was just being inconsistent. The quotes around a String literal key in a map are optional.

Dave

Generic-user-small
25 Jul 2009, 03:12
Marc Hollins (5 posts)

Thanks for the reply.

So the key in both lines is a String? How does Groovy know it is a String and not another Object instance?

Thanks

Dklein_tiny_pragsmall
27 Jul 2009, 00:59
Dave Klein (34 posts)

I don’t have the official word on this, so you may want to ask on the Groovy mailing list, but from my experimenting, the only way I have been able to use an object reference for a Map key is to put parentheses around it like this:

def x = new Foo()

def map1 = [x:1] // key is a String def map2 = [(x):1] // key is a Foo

Hope that helps, Dave

Generic-user-small
27 Jul 2009, 02:32
Marc Hollins (5 posts)

Very interesting. I’m still getting used to the groovy way of things. I was thinking in Java Mode, where the key to a map can be any Object, but to be honest, I can’t think of a good reason why I would need it.

Thanks again for the reply, and I’m enjoying the book very much.

Marc

You must be logged in to comment