cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hohls" <>
Subject Re: Continuations and cleaning up
Date Thu, 04 Nov 2004 11:02:06 GMT

Do you know of any sample code that shows how the
"someService" code could be implemented?

>>> 2004/11/04 12:41:15 PM >>>
Smith, Lee [OS-IE] wrote:
> Hey All,
> New user to cocoon here, and I've got a question about the use of
> continuations in flow scripts.
> I'll explain my question with the following block of code:
>  1: function myFunc()
>  2: {
>  3:    var myDB = Database.getConnection("myPool");
>  4:    myDB.setAutoCommit(false);
>  5:
>  6:    .. do some work on the connection, don't commit
>  7:
>  8:    cocoon.sendPageAndWait("confirm_changes.html");
>  9:    
> 10:    if (cocoon.request.getParameter("confirm_changes") == "true")
> 11:       myDB.commit();
> 12:    else
> 13:       myDB.rollback();
> 14:
> 15:    cocoon.sendPage("change_made.html");
> 14: }
> In this example I get a connection to a database, make some changes
and then
> allow the user to confirm they are happy with the changes and then
> upon their response, either commit them or roll them back.
> Now this is all fine assuming the user follows the confirmation or
> cancellation links on the page - however, assuming there is a menu
system on
> the confirmation page it is possible for the user to break out of
> continuation without completing it, hence leaving uncommitted changes
in the
> database.
> Is there anyway I can trap the user activating links on the site
> they activate another resource in the current site-map)? I have a
feeling I
> may be thinking about this in too much of a Java-ish way and there
should be
> another way I should be doing this :)
> I'm expecting somebody to say "Why not let the user confirm any
> before applying them to the database", well the reason for doing this
is it
> allows me to trap any errors (ie. things like duplicate keys, or
> foreign keys) that show up when you apply the changes to the db and
> show these to the user before I ask them if they are happy with the
As you might think this is not a good way to go. You should organize
business logic into services that are separate from user flow. That
means you 
first you have to ask for user confirmation, then go with the changes.
Even if 
your service fails to update the database you still can report the
error to 
the user and send him back to editing to correct the errors:

var error = null;
while( true ) {
	form.showForm( "edit-data", bizData ); bean );
	try {
		someService.performAction( bean );
		cocoon.redirectTo( "mainpage" );
	} catch( e ) {
		error = e;
	if ( error != null ) {
		cocoon.sendPageAndWait( "errorHasOccured",
					{ exception: error} );

This code loops until the service gets properly executed. Still the
user can 
follow other link and leave the continuation which in turn will expire
some time.

No problem witch resource management. No problem with scalability
open connections while user drinks coffee is a BadThing (tm)). Also you
make your service testable which could be PITA in your approach.

Leszek Gawron                            

Project Manager                                    MobileBox sp. z
+48 (61) 855 06 67                    

mobile: +48 (501) 720 812                       fax: +48 (61) 853 29

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.

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

View raw message