1
votes

In Grails 1.3.7, the default controllers would produce code like the following for the display of flash messages in the save action for a domain class (just notice the start of the assignment, i.e. the "${ ):

 flash.message = "${message(code: 'default.created.message', args: [message(code: 'issue.label', default: 'Issue'), issueInstance.id])}"

In Grails 2.0, this is changed to

 flash.message = message(code: 'default.created.message', args: [message(code: 'issue.label', default: 'Issue'), issueInstance.id])

Where we can note the difference is at the start of the assignment. In 1.3.7, apparently a string is passed to be evaluated inside the gsp, at "gsp compile-time / run-time?". It appears this no longer needed in Grails 2.0. Is this because of a changed / improved Groovy capability? In short, I'm trying to understand what's different about Grails that passing a message that evaluates inside the GSP is no longer needed, and where one can take advantage of this difference/change in Grails 2.0 in general.

Thanks, Ray

1
I didn't know that (perhaps the writer(s) of the default Grails controller didn't know that one doesn't need to do the former syntax either?). I think I'm simply looking for clarity in how strings/things evaluate in gsps. Thanks for your reply, please let me know if you have additional knowhow on that.Ray

1 Answers

1
votes

I think the second (Grails 2.0) way is a bit cleaner. Since both the alternatives essentially evaluate to the same String, there doesn't seem to be any value in the first one being evaluated in a GString. The fact that it is a GString means that it'll be doing the extra expression (${...}) processing (so will be marginally slower), whereas the Grails 2.0 version just goes straight to the message taglib.

Not sure why it was originally done the first way... BTW, I don't think the code inside the GString is evaluated during the GSP processing - it is evaluated at the time the GString is assigned to flash.message in the controller (same time as the Grails 2.0 version)...