Struts Flow is a port of Cocoon's <http://cocoon.apache.org> Control Flow <http://cocoon.apache.org/2.1/userdocs/flow/index.html> to Struts <http://struts.apache.org> to allow complex workflow to be implemented using continuations-capable JavaScript. It provides the ability to describe the order of Web pages that have to be sent to the client, at any given point in time in an application. The code is based on a proof-of-concept Dave Johnson put together <http://rollerweblogger.org/comments/roller/blog/jsp_control_flow_engine> to show how the Control Flow could be extracted from Cocoon.

While the initial target of the extracted Control Flow is Struts, the Flow code is reusable from other non-Struts environments. This means Control Flow could be used to drive non-Struts JSP applications, portlets, or even complex web services.

For more information, see the project's temporary website: http://struts.sf.net/struts-flow

To show the code in action, here is the implementation of a number guessing game:

function main() {

 var random =  Math.round( Math.random() * 9 ) + 1;
 var hint = "No hint for you!"
 var guesses = 0;

 while (true) {

// send guess page to user and wait for response
forwardAndWait("failure", { "random" : random, "hint" : hint,
"guesses" : guesses} );


// process user's guess
var guess = parseInt( getRequestParams().guess );
guesses++;
if (guess) {
if (guess > random) {
hint = "Nope, lower!"
} else if (guess < random) {
hint = "Nope, higher!"
} else {
// correct guess
break;
}
}
}


// send success page to user
forwardAndWait("success", {"random" : random, "guess" : guess, "guesses" : guesses} );
}


Don


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to