Today I decided to refactor the flow-driven feedback wizard in the samples:
http://localhost:8080/cocoon/samples/xmlform/flow
In particular, I wanted to get rid of the inlined validation function definitions in the calls to Xform.sendview ().
So I went into feedbackWizard.js and defined a userinfo object with a member, bean, and the two validation functions defined as methods.
However when I restarted Cocoon, it looks like XForm.sendView is not getting the validation function passed to it, as when I enter data that would trigger the validator, it's ignored, and only the Schematron validation's applied.
I know that passing a function as data in JavaScript's a little non-obvious.
---- Here's my revisions to feedbackWizard.js
// XML Form Feedback Wizard Application
cocoon.load("resource://org/apache/cocoon/components/flow/javascript/ xmlForm.js");
/** * Constructor for UserInfo object */ function UserInfo () { this.bean = null; }
/** * Validate UserIdentity * @param xform XForm object */ function UserInfo_validateUserIdentity (xform) { var bean = xform.getModel(); print("I can also do validation in JavaScript"); print("age = "+xform.getValue("number(/age)")); print("role = "+bean.role); if (bean.age > 40) { xform.addViolation("/age", "Hey, you're too old"); } }
UserInfo.prototype.validateUserIdentity = function (xform) { UserInfo_validateUserIdentity (xform); }
/** * Validate Deployment * @param xform XForm object */ function UserInfo_validateDeployment (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"); } }
UserInfo.prototype.validateDeployment = function (xform) { UserInfo_validateDeployment (xform); }
function feedbackWizard(xform) { var userinfo = new UserInfo (); userinfo.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", "Executive"], system: { os: "Unix", processor: "p4", ram: 512, servletEngine: "Tomcat", javaVersion: "1.3", } }
xform.setModel(userinfo.bean);
xform.sendView("userIdentity", "userIdentity.xml", userinfo.validateUserIdentity (xform));
// move this into a method of UserInfo
/* function(xform) { */ /* var bean = xform.getModel(); */ /* print("I can also do validation in JavaScript"); */ /* print("age = "+xform.getValue("number(/age)")); */ /* print("role = "+bean.role); */ /* if (bean.age > 40) { */ /* xform.addViolation("/age", "Hey, you're too old"); */ /* } */ /* }); */ print("handling user identity");
xform.sendView("deployment", "deployment.xml", userinfo.validateDeployment (xform));
// move this into a method of UserInfo
/* 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", "system.xml"); print("handling system");
xform.sendView("confirm", "confirm.xml"); print("handling confirm");
xform.finish("end.xml"); print("done"); }
-- whump
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]