cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobia <>
Subject Redirect at the end of a form
Date Mon, 04 Jun 2007 10:32:47 GMT
Cocoon users,

I would like to get your feedback on a piece of flowscript I just wrote
to solve what I believe to be a common problem.

Suppose you have a form that asks the user for some data, validates it
and inserts it into a database, using a DB access layer for flowscript,
such as jdbi.js from the samples.  The basic flowscript would be:

	// create and show the form
	var form = new Form(...)

	/* execute DB operations to store the newly inserted data */

	//send a results page back to the user

The final sendPage() sends a custom page to show the user what he has
just inserted.  Suppose also that said data does not have a public url,
but is only available to the submitting user at the end of the form.

What is the problem with the previous flowscript?  If the user reloads
the final page, the DB operations are executed again, possibly resulting
in duplicate insertions or other errors.

The usual solution to this problem is to issue a client-side redirect to
a GET url, so that subsequent client reloads don't have side effects.

Continuations seem the perfect tool to issue such a redirect to a
private url built on-the-fly for just one user, but I couldn't find an
idiomatic way of doing it in the samples, so I wrote my own.

The following function is called after the DB operations, just before
the final sendPage()

	function redirectToGet() {
	  var done = false
	  var cont = cocoon.createWebContinuation()
	  if (! done) {
	    done = true
	    var url = /* build a url that will call */
	    cocoon.redirectTo(url, true)

What do you think?  Is there a better way of doing it?  How is this
problem usually solved?  Any feedback is welcome.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message