Use Continuations to Develop Complex Web Applications
By Abhijit Belapurkar2005-04-22
Resuming the Continuation
Resuming the continuation essentially brings control back to the script on the line immediately following the call to sendPageAndWait. The next two lines extract the rate and qty parameters from the request. The next continuation is generated when the sendPageAndWait call is made for the page/getZone page, which maps to the physical file screens/getZone.xml. This call also takes a map consisting of name/value pairs, which here are basically the two parameters submitted by the user in the previous page.
To better understand how these name/value pairs work, take a look at the XML file underlying the /getZone page, shown in Listing 6:
Listing 6. The XML file underlying the getZone page
<?xml version="1.0"?>This page is geared to display to the user the values he entered for the rate and quantity in the previous page. You will notice that the placeholders in this XML file are #{qty} and #{rate} -- these names will be looked up in the map and automatically replaced by the corresponding values from the map when the HTML page is being assembled. As before, the action field of this form points to the continuation id for the given page, which represents the child continuation of the continuation generated for the getRateAmt page.
<page>
<title>Get Buyer Category and Delivery Option</title>
<content>
<form method="post" action="continue.#{$cocoon/continuation/id}">
<para>You are buying #{qty} items, at #{rate} apiece</para>
<para>Please specify your category:<br/>
<input type="radio" name="zone" value="A">A</input><br/>
<input type="radio" name="zone" value="B">B</input><br/>
<input type="radio" name="zone" value="C">C</input><br/>
</para>
<para>Will you be picking up the item yourself from our warehouse,
or would you like it shipped?<br/>
<input type="radio" name="delOpt" value="P">Pickup</input><br/>
<input type="radio" name="delOpt" value="S">Shipping</input><br/>
</para>
<input type="submit" name="submit" value="Next"/>
</form>
</content>
</page>
The rest of the application flow in Listing 4 can be understood in a similar fashion. One interesting thing to note is that the page getShipOpt will be shown to the user only if he selected "S" for getting the purchased items shipped. If the user has selected that option, a new continuation will be generated. If the user has selected "P" for pickup, then the getShipOpt page doesn't have to be shown, and, hence, no continuation will be generated.
Tutorial Pages:
» A Programming Paradigm to Simplify MVC for the Web
» What is a Continuation, Anyway?
» Problems in Conventional Web development
» The Case for Continuations
» User-Centered Navigation
» You Make the Rules!
» The Continuations Repository
» An Example Application
» Web Continuations in Apache Cocoon
» The Application Sitemap
» The Application Logic
» Understanding the Application Logic
» Resuming the Continuation
» JavaScript vs. the Java language
» Continuations in Java code
» Pros and Cons of Continuations
» Conclusion
» Resources
First published by IBM DeveloperWorks
