Adapted from Tony Collen's GettingStartedWithFlow page on the Cocoon wiki.
In this example, an HTML form is shown repeatedly, until the user guesses the correct number.
Start the game here.
At the sitemap level, Flowscript applications need four things:
Note that this already contains the declaration of the next example's Flowscript.
Here we use variables to allow any Flowscript function to be called, with a simple security restriction: the function name must start with the public_ prefix.
The maxValue parameter is used by our Flowscript public_startGuessNumber function, but doesn't hurt if it is passed to other functions (like in the next example).
This activates a Flowscript continuation when an URL ending with a continuation ID and the .continue suffix is received.
To be able to include data provided by Flowscript in our forms and views, we use the Flowscript-aware JXTemplateGenerator
Here's the pipeline
Which uses this resource to convert the page to HTML
And here's the JXTemplate component declaration
Here's the complete Flowscript code that drives the number-guessing game. (sorry about the lost indentation, the Slop block, which generates these listings, has been improved in the meantime).
The JXTemplateGenerator makes Flowscript variables (like the toGuess and hint attributes of the sendPageAndWait call above) accessible using a simple substitution syntax.
Here's the page definition for our number-guessing form. JXTemplate codes like ${cocoon.continuation.id}, will by replaced by values provided in the Flowscript sendPageAndWait function call.
We have now seen the complete code of our Flowscript application: