[Maypole] Problem with Cookbook Method
Jim Abraham
jcabraham@genpathpharma.com
Wed, 12 May 2004 11:18:30 -0400
This is from the "Maypole Request Hacking Cookbook" at
http://maypole.simon-cozens.org/doc/Request.html
# clip
Template Switcheroo
An action doesn't have any data of its own to display, but needs to
display something.
Solution: This is an extremely common hack. You've just issued an action
like beer/do_edit, which updates the database. You don't want to display
a page that says "Record updated" or similar. Lesser application servers
would issue a redirect to have the browser request /beer/view/id
instead, but we can actually modify the Maypole request on the fly and,
after doing the update, pretend that we were going to /beer/view/id all
along. We do this by setting the objects in the objects slot and
changing the template to the one we wanted to go to.
This hack is so common that it's expected that there'll be a neater way
of doing this in the future.
# end clip
The problem with updating the database and then internally switching to
another display page, rather than sending a redirect to a display page
is that, if the user then, for whatever, idiotic reason, clicks Reload
on that page, he will at the very least get an annoying "POST data"
message from the browser, or, at worst, repost the edit page and do a
redundant database write.
What surprises me is that this behavior (the dreaded "Reload" effect) is
"so common" that most developers have already been burned by the
internal page switch "bug". This "solution" should probably be rethought.
Jim Abraham