Christopher Oliver wrote:

Vadim Gritsenko wrote:

As I mentioned in another email - makeWebContinuation method does not set parent.


It looks like it does to me.


Seems I'm not good story teller ;-) Ok, attached please find code which is improvement on Calculator sample, and below attempt to explain.

Currently, sendPageAndWait creates a continuation, adds it to the tree by adding it to the current "lastContinuation", sets this continuation as a last one, and sends response to the browser. When you submit page with this continuation, script continues from the point where you called sendPageAndWait.

You can submit this same page with this same continuation multiple times (if continuation is not expired), so it is sort-of re-usable URI. But, this URI is intended to be POST-only, as script expects some data back (and it was the reason of showing the page). So, you can't use this re-usable URI as a "bookmark". For a bookmark, you need GET-friendly URI.

Such bookmarkable URIs can be created by another method. Actually, this method provides the only alternative to the creation of the continuations via sendPageAndWait. This method is makeWebContinuation() in FOM_Cocoon. As it is not exposed to the Javascript, you can call this method by writing helper (example: org.apache.cocoon.woody.flow.javascript.Woody).

Now, when thinking about this method, what it actually mean and how it relates to the sendPageAndWait? I think about this method as "do not send page, do not wait, but return continuation anyway" (kind of loopback version of sendPageAndWait). Thus, it will create continuation right here, right now, and it will be GET friendly continuation which you can use to create bookmarks, navigation bars, etc.

There is one issue though: current version of createWebContinuation (a.k.a. "do not send page, do not wait, but return continuation anyway") does not do any manipulations with the lastContinuation object in FOM_Cocoon. As a result, all "boomarks" will be unconnected continuations unless you manually connect them (see attached calc.js). And after going through the demo, you can see in the log that continuation tree(s) created by sendPageAndWait are not connected to "bookmarkable" continuations.

This creates a problem when you need to invalidate all the continuations created during application session.

So, there are couple of ways to solve the issue.
(a) Manually chain continuations:
parent.addChild(cocoon.sendPageAndWait("page/getOperator", bizData));
(b) Modify makeWebContinuation to behave same as sendPageAndWait with the only difference of not actually sending any page.

I'm in favor of (b) as it is more consistent. So, my proposal is:

(a) Modify makeWebContinuation to behave same as sendPageAndWait w.r.t. lastContinuation
(b) Expose makeWebContinuation in the Javascript.
(c) Using makeWebContinuation, system.js can be extended to include bookmark() Javascript function.


WDYT?

Vadim

Attachment: calc.js
Description: JavaScript source

<?xml version="1.0"?>

<!--+
    | CVS: $Id: getOperator.xsp,v 1.4 2003/10/22 16:56:21 joerg Exp $
    | Author: Ovidiu Predescu "[EMAIL PROTECTED]"
    | Date: March 23, 2002
    +-->

<xsp:page language="java"
          xmlns:xsp="http://apache.org/xsp";
          xmlns:jpath="http://apache.org/xsp/jpath/1.0";>
  <page>
    <resources>
      <resource type="file" href="calc.js">Flowscript</resource>
    </resources>
    <title>Calculator</title>
    <content>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="root/id"/></xsp:expr></xsp:attribute>Start Over</a>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="back/id"/></xsp:expr></xsp:attribute>Go Back</a>

      <form  method="post">
        <xsp:attribute name="action"><xsp:expr>"continue." + <jpath:continuation/></xsp:expr></xsp:attribute>
        <para>a = <strong><jpath:value-of select="a"/></strong></para>
        <para>b = <strong><jpath:value-of select="b"/></strong></para>
        <para>Enter operator
          <select name="operator">
            <option>plus</option>
            <option>minus</option>
            <option>multiply</option>
            <option>divide</option>
          </select>
        </para>
        <input type="submit" name="submit" value="Do it!"/>
      </form>
    </content>
  </page>
</xsp:page>
<?xml version="1.0"?>

<!--+
    | CVS: $Id: displayResult.xsp,v 1.4 2003/10/22 16:56:21 joerg Exp $
    | Author: Ovidiu Predescu "[EMAIL PROTECTED]"
    | Date: March 23, 2002
    +-->

<xsp:page language="java"
          xmlns:xsp="http://apache.org/xsp";
          xmlns:jpath="http://apache.org/xsp/jpath/1.0";>
  <page>
    <resources>
      <resource type="file" href="calc.js">Flowscript</resource>
    </resources>
    <title>Calculator</title>
    <content>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="root/id"/></xsp:expr></xsp:attribute>Start Over</a>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="back/id"/></xsp:expr></xsp:attribute>Go Back</a>

      <form action="./" method="post">
        <para>a = <strong><jpath:value-of select="a"/></strong></para>
        <para>b = <strong><jpath:value-of select="b"/></strong></para>
        <para>Operator = <strong><jpath:value-of select="operator"/></strong></para>
        <para>Result = <strong><jpath:value-of select="result"/></strong></para>
        <input type="submit" name="submit" value="Start over"/>
      </form>
    </content>
  </page>
</xsp:page>
<?xml version="1.0"?>

<!--+
    | CVS: $Id: getNumberA.xsp,v 1.4 2003/10/22 16:56:21 joerg Exp $
    | Author: Ovidiu Predescu "[EMAIL PROTECTED]"
    | Date: March 23, 2002
    +-->

<xsp:page language="java"
          xmlns:xsp="http://apache.org/xsp";
          xmlns:jpath="http://apache.org/xsp/jpath/1.0";>
  <page>
    <resources>
      <resource type="file" href="calc.js">Flowscript</resource>
    </resources>
    <title>Calculator</title>
    <content>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="root/id"/></xsp:expr></xsp:attribute>Start Over</a>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="back/id"/></xsp:expr></xsp:attribute>Go Back</a>

      <form method="post">
        <xsp:attribute name="action"><xsp:expr>"continue." + <jpath:continuation/></xsp:expr></xsp:attribute>
        <para>
          Enter value of <strong>a</strong>:
          <input type="text" name="a">
            <xsp:attribute name="value"><jpath:value-of select="a"/></xsp:attribute>
          </input>
        </para>
        <input type="submit" name="submit" value="Enter"/>
      </form>
    </content>
  </page>
</xsp:page>
<?xml version="1.0"?>

<!--+
    | CVS: $Id: getNumberB.xsp,v 1.4 2003/10/22 16:56:21 joerg Exp $
    | Author: Ovidiu Predescu "[EMAIL PROTECTED]"
    | Date: March 23, 2002
    +-->

<xsp:page language="java"
          xmlns:xsp="http://apache.org/xsp";
          xmlns:jpath="http://apache.org/xsp/jpath/1.0";>
  <page>
    <resources>
      <resource type="file" href="calc.js">Flowscript</resource>
    </resources>
    <title>Calculator</title>
    <content>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="root/id"/></xsp:expr></xsp:attribute>Start Over</a>
      <a><xsp:attribute name="href"><xsp:expr>"continue." + <jpath:value-of select="back/id"/></xsp:expr></xsp:attribute>Go Back</a>

      <form method="post">
        <xsp:attribute name="action"><xsp:expr>"continue." + <jpath:continuation/></xsp:expr></xsp:attribute>
        <para>a = <strong><jpath:value-of select="a"/></strong></para>
        <para>
          Enter value of <strong>b</strong>:
          <input type="text" name="b">
            <xsp:attribute name="value"><jpath:value-of select="b"/></xsp:attribute>
          </input>
        </para>
        <input type="submit" name="submit" value="Enter"/>
      </form>
    </content>
  </page>
</xsp:page>

Reply via email to