The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jeroend (23) [Avatar] Offline
#1
meap v6.
I noticed that the use of closures was already reported, but I'm still wondering why in listing 6.4 you need a redirect after the post has been added and why can't addPost just not simply return the outcome of timeline([id:params.id])?
What's the difference with forward and would it make a difference when using grails 2.0 methods?

see also this SO question and the comments on accepted answer:
http://www.manning-sandbox.com/post!default.jspa?forumID=830

Message was edited by: author
jeroend
peter.ledbrook (328) [Avatar] Offline
#2
Re: 6.4 redirect
I don't think that's the link you meant to post smilie

As for the addPost action, the user experience is better when a client-side redirect is issued after a post. Otherwise a refresh of the page will result in the user being asked whether he or she wants to resubmit the data.

It's also important to understand that actions cannot simply hand off the request handling to another action unless a redirect() or forward() is involved. The difference between those two is that redirect() sends a 302 response back to the client (browser), which then sends a GET request to the target action straight away, whereas forward() internally offloads the request handling to the target action, and it's the target action's responsibility to render the view (or do whatever is necessary).

forward() can be useful, but the refresh behaviour means that a redirect() is better in this case. Otherwise you have the timeline rendering under a non-timeline URL (in fact the user will see the URL /hubbub/post/addPost in his or her address bar).

Neither of these approaches are affected by the switch to methods as actions in Grails 2.0.