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 Mon, 24 Feb 2003 04:00:46 GMT
ivelin wrote:
> Chris,
> 
> I am trying to get my hands around your code.
> I see the function which loops until there are no more input violations and
> although I have a guess about the response, I would still like to hear from
> you on these questions:
> 
> Where would you place calls to the backend which for example pull data from
> a database to populate the bean for the next page?
> Where would if place logic which decides what is the next page based on
> input choices made on the current page?
> 
> 
> -=Ivelin=-
> 
> 

Below is a variation of the feedback wizard example that should answer 
your questions. Where you see

         print("handling xxxxx")

that is where you would perform back-end actions like reading from a 
database, as well as where you would decide which page to send next 
based on the values set in the bean by the previous page. The contrived 
example below shows the deployment and system pages in reverse order if 
the "age" you enter in the userIdentity page is greater than 20.

Regards,

Chris





// XML Form Feedback Wizard Application


function deployment(xform) {
     xform.sendView("deployment",
                    "flow/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");
}

function system(xform) {
     xform.sendView("system", "flow/system.xml");
     print("handling system");
}

function feedbackWizard(xform) {
     var bean = {
     firstName: "Donald",
     lastName: "Duck",
     email: "donald_duck@disneyland.com",
     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", "Executive"],
     system: {
         os: "Unix",
         processor: "p4",
         ram: 512,
         servletEngine: "Tomcat",
         javaVersion: "1.3",
     }
     }
     xform.setModel(bean);
     xform.sendView("userIdentity",
            "flow/userIdentity.xml",
                    function(xform) {
     var bean = xform.getModel();
         print("I can also do validation in JavaScript");
     print("age = "+xform.xpath("number(/age)"));
     print("role = "+bean.role);
         if (bean.age > 40) {
             xform.addViolation("/age", "Hey, you're too old");
         }
     });
     print("handling user identity");
     if (bean.age > 20) {
        system(xform);
        deployment(xform);
     } else {
        deployment(xform);
        system(xform);
     }
     xform.sendView("confirm", "flow/confirm.xml");
     print("handling confirm");
     xform.finish("end", "flow/end.xml");
     print("done");
}


Mime
View raw message