cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Re: XMLForm/Flow Integration
Date Wed, 19 Feb 2003 02:01:49 GMT
Ugo Cei wrote:

> I didn't try the sample, since it's 1AM and I'm going to bed, but just 
> by looking at the code, I have a couple of observations:
>
>>              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)
>
>
> Sometimes, the validation you can perform with Schematron is not 
> enough.  In my application, I have a form for user registration and, 
> besides checking that the username is present, email address is valid 
> and passwords match, I need to check that the username is not already 
> registered. To do this, I need to query the database and, if a 
> duplicate is found, create a new violation object and attach it to the 
> form. How can I do that if the validation logic is hidden inside 
> XForm.sendView?
>
OK. The attached should allow you to also perform validation in 
JavaScript.  XForm.sendView() now looks like this

      XForm.sendView(view, uri, validator);  


where the (optional) "validator" parameter is a JavaScript function that 
will be invoked after the form is populated. XForm now also supports a 
method to add violations

      XForm.addViolation(xpath, message);   // both parameters are strings

which you can use to report violations.

Here's an example with the feedback wizard:

// XML Form Feedback Wizard Application

importPackage(Packages.org.apache.cocoon.samples.xmlform);

function feedbackWizard(xform) {
    var bean = new UserBean();
    xform.setModel(bean);
    xform.sendView("userIdentity", "wizard/userIdentity.xml");
    print("handling user identity");
    xform.sendView("deployment",
                   "wizard/deployment.xml",
                   function() {
        print("I can also do validation in JavaScript")
        if (bean.publish) {
            xform.addViolation("/publish", "Sorry, I won't let you 
publish ");
        }
    });
    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");
    print("done");
}


Mime
View raw message