Note: in this implementation there is a 1-1 mapping between validation phases and views.
Please test these changes and let me know if they work and if they make sense.
The Cocoon flow layer now supports using JavaScript objects as well as Java beans, DOM and JDOM objects (or anything else compatible with JXPath, see http://jakarta.apache.org/commons/jxpath).
This means you can pass a JavaScript object to sendPage*() and access its properties with jpath:value-of in an xsp page. It also means that the model you use for your XMLForm can be a JavaScript object.
I've added the XMLForm JavaScript API to system.js (http://cvs.apache.org/viewcvs.cgi/*checkout*/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/system.js?rev=1.7&content-type=text/plain)
Here is a summary of the methods of the JavaScript XForm:
/** * Assign the model for this form * @param bean Any Java Bean, DOM, JDOM, or JavaScript object */ setModel([Object] bean)
/** * Return the model used by this form * @return a Java Bean, DOM, JDOM or JavaScript object */ getModel()
/** * Sends view to a presentation pipeline and waits for subsequent * submission. Automatically resends view if validation fails. * Creates two continuations: one immediately before the page submission * and one immediately after. These are used to implement automated * support for back/forward navigation in the form. When you move * forward in the form the second continuation is invoked. When you move * back from the following page the first continuation is invoked. * * @param view View to send (and phase to validate) * @param uri presentation pipeline resource identifier * @param validator optional function invoked to perform validation * after the form is populated. The function will be passed the * form as its only parameter. * */ sendView([String] view, [String] uri, [Function] validator)
/** * Sends view to a presentation pipeline but doesn't wait for submission * All continuations associated with the form are invalidated. * * @param view view to send * @param uri presentation pipeline uri */ finish([String] view, [String] uri)
/** * Adds a violation to this form * @param xpath XPath expression referencing the field that contains invalid data * @param message Error message */ addViolation([String] path, [String] message)
/** * Computes the value of an xpath expression against the model of this * form. Useful for testing your model in the Cocoon flow debugger or * doing "println" debugging. * @param expression Any XPath expression * @return Result of computing expression against this form's model */ xpath([String] expression)
Regards, Chris