cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <>
Subject XMLForm/Flow Integration
Date Tue, 18 Feb 2003 23:21:24 GMT
Attached is a first try at integrating XMLForm with the Cocoon Flow 
layer. Since I'm not an expert on XMLForm or XForms  (or Cocoon for that 
matter!) it's likely to have limitations or defects so keep that in mind.

The attached files provide an implementation of the XMLForm Feedback 
Wizard sample, but any XMLForm application should be easy to convert to 
use the Flow layer instead of actions. Here is the flow version of the 
Feedback Wizard sample (see feedbackWizard.js):

// XML Form Feedback Wizard Application


function feedbackWizard(xform) {
    xform.setModel(new UserBean());
    xform.sendView("userIdentity", "wizard/userIdentity.xml");
    print("handling user identity");
    xform.sendView("deployment", "wizard/deployment.xml");
    print("handling deployment");
    xform.sendView("system", "wizard/system.xml");
    print("handling system");
    xform.sendView("confirm", "wizard/confirm.xml");
    print("handling confirm");
    xform.finish("end", "wizard/end.xml");

To try the flow version of the feedback wizard, do the following:

1) Save xmlform.js, feedbackWizard.js, and sitemap.xmap in 
2) Save confirm.xml, deployment.xml, end.xml, start.xml, system.xml. and 
useIdentity.xml in src/webapp/samples/xmlform/wizard
3) Save in 

Below is description of what I did (and what you'd need to do to migrate 
your own XMLForm application).

Let me know if you have problems running the sample and give me your 
feedback on this approach to integrating XMLForm and Flow.



1) Write a JavaScript function that represents your page flow (see 
feedbackWizard.js for an example). This function will be called with one 
parameter which is a JavaScript version of the XMLForm object. This 
object has the following methods:

              XForm.setModel(bean)  // Assign "bean" as the model for 
this form
              XForm.sendView(view, uri)  // Sends "view" to the 
presentation pipeline and waits for the form to be submitted (and 
automatically resends it if validation fails)
              XForm.finish(view, uri)  // Sends "view" to the 
presentation pipeline but doesn't block

Internally, this object delegates to an instance of 
org.apache.components.xmlform.Form and uses standard XMLForm 
functionality. Its implementation is in the attached "xmlform.js".

2) To support bidirectional navigation in your forms simply modify your 
XMLForm document's <xf:submit> elements to include an additional 
attribute called "continuation". The value for this attribute should be 
"back" to go back or "forward" to go forward.  I modified  
XMLFormTransformer (see attached) to substitute the proper continuation 
id for the "id" attribute in <xf:submit> when the "continuation" 
attribute is present. I've attached accordingly modified versions of the 
XMLForm Feedback wizard documents. For example, here's the relevant 
snippet from "system.xml":

   <xf:submit id="prev" continuation="back" class="button">
      <xf:hint>Go to previous page</xf:hint>
    <xf:submit id="next" continuation="forward" class="button">
      <xf:hint>Go to next page</xf:hint>

3) Modify your sitemap to call the "xmlForm" Flow function instead of 
your Action. Here are the relevant snippets from the attached sitemap

<!-- Add an entry for the flow layer to load your scripts  -->
  <map:flow language="JavaScript">
      <map:script src="xmlform.js"/>
      <map:script src="feedbackWizard.js"/>

<!-- Add a pipeline that calls the "xmlForm" Flow function instead of an 
action. This takes the same parameters as an XMLForm action -->
<!-- In addition, it takes one additional parameter (xml-form-function) 
which is the name of the application function from (1) above -->
<!-- Note: you must specify the parameters in the order below! -->

      <map:match pattern="wizard">
        <map:call function="xmlForm">
            <map:parameter name="xml-form-function" value="feedbackWizard"/>
            <map:parameter name="xml-form-id" value="form-feedback"/>
            <map:parameter name="xml-form-validator-schema-ns" 
            <map:parameter name="xml-form-validator-schema" 
            <map:parameter name="xml-form-scope" value="session"/>

<!-- move the presentation pipeline out of the action so it can be 
called from the flow layer -->
      <map:match pattern="wizard/*.xml">
          <!-- original XMLForm document -->
          <map:generate src="wizard/{1}.xml"/>
          <!-- populating the document with model instance data -->
          <map:transform type="xmlform"  label="xml"/>
          <!-- personalizing the look and feel of the form controls  -->
          <map:transform type="xalan" src="stylesheets/wizard2html.xsl" />
          <!-- Transforming the XMLForm controls to HTML controls -->
src="context://samples/stylesheets/xmlform/xmlform2html.xsl" />
          <!-- sending the HTML back to the browser -->
          <map:serialize type="html" label="debug"/>

View raw message