Details:

   * Cocoon 2.1.7 standalone
   * JDK 1.5.0_03
   * Windows 2000 SP4


I have made a small example to test the use of continuations, it is made of a simple counter that is incremented each time the user presses the "count" button, then, when the "stop" button is pressed, the result page, containing the final value of the counter, is sent. On the basis of what I have understood about continuations, I expected that, pressing the "BACK" button of the browser, old continuations should be restored and local variables should be restored with them, for example: I press "count" five times, so the value is now 5 (assuming the initial value equal to zero), now I press the back button two times (I expect the value to be restored to three) and in the end I press the "stop" button ... but the result shown is still 5, and not 3 as expected!
What's wrong with my aproach?


The official documentation says:

/"With continuations in the language, you can essentially store the continuation of |sendPageAndWait()| (think of all the stack trace, and the program counter), put it in a global hash table associated with an id. The id is then encoded in the |response.xml| page as an URL. When the user clicks on that URL, on the server side the associated continuation is resumed. Resuming the processing happens as if nothing was stopped, you get all the stack trace back, and all the local variables.// So instead of using beans to store things in session, you use normal variables in a program. Since each user has its own version of the program, all the local variables in the program are separate between users. With this approach clicking the Back button in the browser is no longer a hassle to deal with for you as a server-side programmer. They will simply refer to past continuations objects, which have their own state of the local variables./

/Since continuations are objects, you can also store them in a database, for really long-lived session, just like you do with session beans."/


Any help or suggestion is very appriciated!
Thanking you in advance.


R. L.


Follows the code:

********** Flowscript ************

function main()
{
 var counter = 0;

 while(true)
 {
   var action = cocoon.request.get("formButton");
   if(action)
   {
       if(action.equals("stop"))
           break;
       else //count
       {
           counter++;
           cocoon.sendPageAndWait("count.jx", {"counter" : counter});
       }
   }
   else
cocoon.sendPageAndWait("count.jx", {"counter" : counter}); }
 cocoon.sendPage("result.jx", {"counter": counter} );
}

*************** count.jx and result.jx *********************

<?xml version="1.0"?>
<html xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
<head>
 <title>Cocoon flow counter</title>
</head>
<body>
   <h1>Counter (partial) value: ${counter}</h1>
   <form action="${cocoon.continuation.id}.kont">
       <input type="submit" name="formButton" value="count"/>
       <input type="submit" name="formButton" value="stop"/>
   </form>
</body>
</html>


<?xml version="1.0"?>
<html xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
<head>
 <title>Cocoon flow counter result</title>
</head>
<body>
 <h1>Counter (final) value: <b>${counter}</b></h1>
 <p><a href="./">Restart</a></p>
</body>
</html>


***************** Sitemap ********************

<?xml version="1.0" encoding="UTF-8"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0";>

<map:components>
 <map:generators default="file">
   <!-- in this example we use JXTemplateGenerator to insert
        Flow variables in page content -->
<map:generator label="content,data" logger="sitemap.generator.jx" name="jx"
       src="org.apache.cocoon.generation.JXTemplateGenerator"/>
 </map:generators>
 <map:transformers default="xslt"/>
 <map:serializers default="html"/>
 <map:matchers default="wildcard"/>
 <map:selectors default="browser">
<map:selector name="exception" src="org.apache.cocoon.selection.XPathExceptionSelector">
     <exception name="invalid-continuation"
class="org.apache.cocoon.components.flow.InvalidContinuationException"/>
     <exception class="java.lang.Throwable" unroll="true"/>
   </map:selector>
 </map:selectors>
 <map:actions/>
 <map:pipes default="caching"/>
</map:components>

<map:views/>
<map:resources/>
<map:action-sets/>

<map:flow language="javascript">
 <!-- Flow will use the javascript functions defined in count.js -->
 <map:script src="flow/count.js"/>
</map:flow>

<map:pipelines>
 <map:component-configurations>
   <global-variables/>
 </map:component-configurations>

 <map:pipeline>
   <!-- no filename: call main() in count.js -->
   <map:match pattern="">
     <map:call function="main"/>
   </map:match>

   <!-- use JXtemplate to generate page content -->
   <map:match pattern="*.jx">
     <map:generate type="jx" src="documents/{1}.jx"/>
     <map:serialize type="xhtml"/>
   </map:match>

   <!-- .kont URLs are generated by the Flow system for continuations -->
   <map:match pattern="*.kont">
     <map:call continuation="{1}"/>
   </map:match>

   <!-- handle invalid continuations -->

   <!-- this style of handling invalidContinuation is now deprecated: -->
   <!-- this URI will never be called automatically anymore. -->
   <!-- see handle-errors below -->
   <map:match pattern="invalidContinuation">
     <map:generate src="documents/invalidContinuation.xml"/>
     <map:serialize type="xml"/>
   </map:match>

   <!-- the new non-hardcoded way of handling invalidContinuation -->
   <map:handle-errors>
     <map:select type="exception">
       <map:when test="invalid-continuation">
         <map:generate src="documents/invalidContinuation.html"/>
         <map:serialize type="xhtml"/>
       </map:when>
     </map:select>
   </map:handle-errors>
 </map:pipeline>

</map:pipelines>

</map:sitemap>



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

Reply via email to