small medium large xlarge

Back to: All Forums  Grails
Generic-user-small
08 Dec 2009, 01:36
Jerome Jahnke (3 posts)

I am struggling with this right now, I am in chapter 7 “Forum Messages and UI Tricks” there is a bunch of code to create the message threaded forums. I have worked my way through this and it doesn’t work. Nor can I understand how it could have worked. My problem is this bit

`

New Message

`

It should create a link with a parameter of “?eventId=n” which it does do but if I look in the list code that was generated by grails I see.

`

New Message

`

Which should generate a link with a parameter of “?event.id=n” which it does. When I use the code from the book the “create” method does not work because an event was not created. BUT if I replace that one line with event.id and it works.

I looked at the sample code and they all follow the eventId prototype but I just tried the code in forum.1 and it did not work on my machine either so I am not sure if I missed something, my env isn’t working or if this just didn’t work? I don’t understand how eventId would have ever worked to be honest but one thing I notice about Grails is that there is a healthy dose of “magic” which makes me think I am missing something somewhere.

Now I will say that I LIKE the look of eventId vs event.id in the url and how would one go about making that work? I guess I could just extract the parameter in the create method and then create event.id parameter in the params object and pass that in.

Jer,

Dklein_tiny_pragsmall
11 Dec 2009, 04:13
Dave Klein (34 posts)

Hi Jerome,

No magic there, just a bug. :( Thanks for catching it and posting here.

The change you made is probably the best one though you could also add the line in bold to the create action:

def create = {
    def messageInstance = new Message()
    messageInstance.properties = params
    *messageInstance.event = TekEvent.get(params.eventId)*
    return ['messageInstance':messageInstance]
}

I’ll get that fixed for future updates.

Thanks again, Dave

Generic-user-small
11 Dec 2009, 07:58
Jerome Jahnke (3 posts)

Thanks for your reply, I ended up doing something close to what you said. Since you use eventId in some other places I just added an event.id attribute to the params object if it did not already exist.

if( params."event.id" == null ) 
    params."event.id" = params.eventId
def messageInstance = new Message()
messageInstance.properties = params
return ['messageInstance':messageInstance]

This also lets me keep the eventId url which I like better. I am just now working through the icing chapter. Thank you very much for the book. I think it has helped cement in my mind what Grails is capable of and I am looking forward to doing some things with it going forward.

Jer,

You must be logged in to comment