Ugo, I will shortly commit changes that will allow you to use any JavaScript object (in addition to Java beans) as the model for an XMLForm. Attached is an example of the feedbackWizard sample using a pure JavaScript model. Of course, you can also embed Java objects inside the JavaScript object. Would this solve your problem? That way you could simply make your Java bean objects (derived from your O/R layer) properties of a larger JavaScript object that serves as the presentation layer model for XMLForm. Any additional information you need could also be stored in it.

Note to all: to make this work I will have to upgrade Cocoon to use JXPath 1.1b1. JXPath 1.0 has bugs that make it unusable for this purpose. Let me know if you think this will be a problem.

Regards,

Chris

Ugo Cei wrote:
I've attached a modified xmlform.js file that implements the following change: the methods "sendView" and "finish" take an extra "bizData" argument that has the same meaning as the "bizData" argument of sendPage and sendPageAndWait. I need this because many of my pages contain forms but also other data that is not tied to the model being edited in the form.

Christopher, please review the proposed change, thank you.

Ugo


// XML Form Feedback Wizard Application

function feedbackWizard(xform) {
    var bean = {
        firstName: "Donald",
        lastName: "Duck",
        email: "[EMAIL PROTECTED]",
        age: 5,
        number: 1,
        liveUrl: "http://";,
        publish: true,
        hidden: true,
        count: 1,
        notes: "<your notes here>",
        favorite: ["http://xml.apache/org/cocoon";, 
                   "http://jakarta.apache.org";,
                   "http://www.google.com";,
                   "http://www.slashdot.com";,
                   "http://www.yahoo.com";],
        hobby: ["swim", "movies", "ski", "gym", "soccer"],
        allHobbies: [
            {
                key: "swim",
                value: "Swimming"
            },
            {
                key: "gym", 
                value: "Body Building"
            },
            {
                key: "ski", 
                value: "Skiing"
            },
            {
                key: "run", 
                value: "Running"
            },
            {  
                key: "football", 
                value: "Football"
            },
            {
                key: "read",
                value: "Reading" 
            },
            {
                key: "write",
                value: "Writing"
            },
            {
                key: "soccer:",
                value: "Soccer" 
            },
            {
                key: "blog",
                value: "Blogging" 
            }],
        role: ["Hacker"],
        system: {
            os: "Linux",
            processor: "p4",
            ram: 512,
            servletEngine: "Tomcat",
            javaVersion: "1.3",
        }
    }
    xform.setModel(bean);
    xform.sendView("userIdentity", 
                   "wizard/userIdentity.xml",
                   function(xform) {
        var bean = xform.getModel();
        print("I can also do validation in JavaScript");
        if (bean.age > 30) {
            xform.addViolation("/age", "Hey, you're too old");
        }
    });
    print("handling user identity");
    xform.sendView("deployment", 
                   "wizard/deployment.xml", 
                   function(xform) {
        var bean = xform.getModel();
        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");
}

Reply via email to