coliver 2003/04/27 15:13:36
Modified: src/scratchpad/src/org/apache/cocoon/components/jxforms/flow
jxForm.js
src/scratchpad/src/org/apache/cocoon/generation
JXFormsGenerator.java
src/scratchpad/webapp/samples/jxforms/flow feedbackWizard.js
src/scratchpad/webapp/samples/jxforms/view userIdentity.xml
Log:
Made validation phase a property of xf:submit rather than a parameter to
sendView()
Revision Changes Path
1.3 +32 -26
cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxforms/flow/jxForm.js
Index: jxForm.js
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxforms/flow/jxForm.js,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- jxForm.js 27 Apr 2003 08:28:51 -0000 1.2
+++ jxForm.js 27 Apr 2003 22:13:35 -0000 1.3
@@ -45,6 +45,14 @@
}
/**
+ * Return the phase of the xf:submit element of the current form submission
+ * @return [String] phase attribute of the button that caused this form to
be submitted
+ */
+JXForm.prototype.getPhase = function() {
+ return this.phase;
+}
+
+/**
* Set the model object of this form
* @param model [Object] Any Java bean, JavaScript, DOM, or JDOM object
*/
@@ -87,7 +95,7 @@
var kont = new WebContinuation(this.cocoon, k,
lastWebCont, timeToLive);
if (this.rootContinuation == null) {
- this.rootContinuation = kont;
+ this.rootContinuation = kont;
}
return {kont: kont};
}
@@ -142,9 +150,9 @@
return this.context.iterate(expr);
}
-JXForm.prototype._sendView = function(uri, lastCont, timeToLive) {
+JXForm.prototype._sendView = function(uri, lastWebCont, timeToLive) {
var k = new Continuation();
- var wk = new WebContinuation(this.cocoon, k, lastCont, timeToLive);
+ var wk = new WebContinuation(this.cocoon, k, lastWebCont, timeToLive);
var bizData = this.form.getModel();
if (bizData == undefined) {
bizData = null;
@@ -163,11 +171,10 @@
* 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 phase [String] phase to validate
- * @param uri [String] presentation pipeline resource identifier of view
+ * @param uri [String] presentation pipeline resource identifier of "view"
* @param validator [Function] optional function invoked to perform
validation
*/
-JXForm.prototype.sendView = function(view, uri, validator) {
+JXForm.prototype.sendView = function(uri, validator) {
var lastWebCont = this.lastWebContinuation;
var wk = this.start(lastWebCont);
while (true) {
@@ -179,8 +186,6 @@
handleInvalidContinuation();
suicide();
}
- // reset the view in case this is a re-invocation of a continuation
- this.cocoon.request.setAttribute("view", view);
this.form.remove(this.cocoon.environment.objectModel, this.id);
this.form.save(this.cocoon.environment.objectModel, "request");
var thisWebCont = this._sendView(uri, wk);
@@ -194,14 +199,16 @@
}
this.form.populate(this.cocoon.environment.objectModel);
this.submitId =
- this.cocoon.request.getAttribute("jxform-submit-id");
+ this.cocoon.request.getAttribute("jxform-submit-id");
+ this.phase =
+ this.cocoon.request.getAttribute("jxform-submit-phase");
if (validator != undefined) {
validator(this);
}
- this.form.validate(view);
+ this.form.validate(this.phase);
if (!this.hasViolations()) {
- this.lastWebContinuation = thisWebCont;
- break;
+ this.lastWebContinuation = thisWebCont;
+ break;
}
}
}
@@ -209,13 +216,13 @@
JXForm.prototype._setValidator = function(schNS, schDoc) {
// if validator params are not specified, then
// there is no validation by default
- if (schNS == null || schDoc == null ) return null;
+ if (schNS == null || schDoc == null) return null;
var resolver = this.cocoon.environment;
- var schemaSrc = resolver.resolveURI( schDoc );
+ var schemaSrc = resolver.resolveURI(schDoc);
try {
var is =
Packages.org.apache.cocoon.components.source.SourceUtil.getInputSource(schemaSrc);
- var schf =
Packages.org.apache.cocoon.components.jxforms.validation.SchemaFactory.lookup (
schNS );
- var sch = schf.compileSchema ( is );
+ var schf =
Packages.org.apache.cocoon.components.jxforms.validation.SchemaFactory.lookup(schNS);
+ var sch = schf.compileSchema(is);
this.form.setValidator(sch.newValidator());
} finally {
resolver.release(schemaSrc);
@@ -238,7 +245,7 @@
if (this.rootContinuation != null) {
this.rootContinuation.invalidate();
this.rootContinuation = null;
- this.lastContinuation = null;
+ this.lastContinuation = null;
}
}
@@ -276,17 +283,16 @@
var command = getCommand();
if (command != undefined) {
// invoke a continuation
- // command looks like kontId:id
- var id = "";
+ // command looks like kontId:phase:id
var kontId = command;
- var index = command.indexOf(java.lang.String(":").charAt(0));
- if (index > 0) {
- var kontId = command.substring(0, index);
- if (index + 1 < command.length()) {
- id = command.substring(index + 1);
- }
+ var izer = new java.util.StringTokenizer(command, ":");
+ if (izer.countTokens() == 3) {
+ kontId = izer.nextToken();
+ var phase = izer.nextToken();
+ var id = izer.nextToken();
+ cocoon.request.setAttribute("jxform-submit-phase", phase);
+ cocoon.request.setAttribute("jxform-submit-id", id);
}
- cocoon.request.setAttribute("jxform-submit-id", id);
cocoon.interpreter.handleContinuation(kontId,
null,
cocoon.environment);
1.4 +41 -27
cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JXFormsGenerator.java
Index: JXFormsGenerator.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JXFormsGenerator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JXFormsGenerator.java 27 Apr 2003 14:56:16 -0000 1.3
+++ JXFormsGenerator.java 27 Apr 2003 22:13:36 -0000 1.4
@@ -172,6 +172,7 @@
final static String BACK = "back";
final static String FORWARD = "forward";
final static String CONTINUATION = "continuation";
+ final static String PHASE = "phase";
/**
@@ -179,7 +180,7 @@
*/
static private CompiledExpression
- compileExpr(JXPathContext context, String expr, Locator location)
+ compileExpr(String expr, Locator location)
throws SAXParseException {
if (expr == null) return null;
try {
@@ -720,7 +721,6 @@
}
static class Parser implements ContentHandler, LexicalHandler {
- JXPathContext context;
StartDocument startEvent;
Event lastEvent;
Stack stack = new Stack();
@@ -728,8 +728,7 @@
Locator charLocation;
StringBuffer charBuf;
- public Parser(JXPathContext context) {
- this.context = context;
+ public Parser() {
}
StartDocument getStartEvent() {
@@ -901,7 +900,7 @@
if (localName.equals(REPEAT)) {
String items = attrs.getValue(NODESET);
CompiledExpression expr =
- compileExpr(context, items, locator);
+ compileExpr(items, locator);
StartRepeat startRepeat =
new StartRepeat(locator, namespaceURI,
localName, raw, attrs, expr);
@@ -909,7 +908,7 @@
} else if (localName.equals(ITEMSET)) {
String items = attrs.getValue(NODESET);
CompiledExpression expr =
- compileExpr(context, items, locator);
+ compileExpr(items, locator);
StartItemSet startItemSet =
new StartItemSet(locator, namespaceURI,
localName, raw, attrs, expr);
@@ -917,7 +916,7 @@
} else if (isReadonlyInputControl(localName)) {
String refStr = attrs.getValue("ref");
CompiledExpression ref =
- compileExpr(context, refStr, locator);
+ compileExpr(refStr, locator);
StartReadonlyInputControl startInputControl =
new StartReadonlyInputControl(locator,
ref,
@@ -927,7 +926,7 @@
} else if (isInputControl(localName)) {
String refStr = attrs.getValue("ref");
CompiledExpression ref =
- compileExpr(context, refStr, locator);
+ compileExpr(refStr, locator);
StartInputControl startInputControl =
new StartInputControl(locator,
ref,
@@ -960,11 +959,9 @@
if (refStr != null && valueStr != null) {
throw new SAXParseException("ref and value are
mutually exclusive", locator, null);
}
- CompiledExpression ref = compileExpr(context,
- refStr,
+ CompiledExpression ref = compileExpr(refStr,
locator);
- CompiledExpression value = compileExpr(context,
- valueStr,
+ CompiledExpression value = compileExpr(valueStr,
locator);
StartOutput startOutput =
new StartOutput(locator,
@@ -985,7 +982,7 @@
} else if (GROUP.equals(localName)) {
String refStr = attrs.getValue(REF);
CompiledExpression ref =
- compileExpr(context, refStr, locator);
+ compileExpr(refStr, locator);
StartGroup startGroup =
new StartGroup(locator,
ref,
@@ -994,7 +991,7 @@
} else if (HIDDEN.equals(localName)) {
String refStr = attrs.getValue(REF);
CompiledExpression ref =
- compileExpr(context, refStr, locator);
+ compileExpr(refStr, locator);
StartHidden startHidden =
new StartHidden(locator,
ref,
@@ -1064,7 +1061,6 @@
public TemplateConsumer(SourceResolver resolver, Map objectModel,
String src, Parameters parameters)
throws ProcessingException, SAXException, IOException {
- super(jxpathContextFactory.newContext(null, null));
this.template = new JXFormsGenerator();
this.template.setup(resolver, objectModel, null, parameters);
}
@@ -1072,9 +1068,10 @@
public void endDocument() throws SAXException {
super.endDocument();
template.execute(template.getConsumer(),
- null,
- null,
- context,
+ null, // form
+ null, // view
+ null, // contextPath
+ jxpathContextFactory.newContext(null, null),
getStartEvent(),
null);
}
@@ -1164,7 +1161,7 @@
}
if (startEvent == null) {
long compileTime = inputSource.getLastModified();
- Parser parser = new Parser(jxpathContextFactory.newContext(null,
null));
+ Parser parser = new Parser();
this.resolver.toSAX(this.inputSource, parser);
startEvent = parser.getStartEvent();
startEvent.compileTime = compileTime;
@@ -1173,8 +1170,9 @@
}
}
execute(consumer,
- null,
- null,
+ null, // form
+ null, // view
+ null, // contextPath
jxpathContextFactory.newContext(null, null),
startEvent,
null);
@@ -1182,11 +1180,11 @@
private void execute(final XMLConsumer consumer,
Form form,
+ String currentView,
String contextPath,
JXPathContext jxpathContext,
Event startEvent, Event endEvent)
throws SAXException {
- String currentView = null;
Event ev = startEvent;
while (ev != endEvent) {
consumer.setDocumentLocator(ev.location);
@@ -1293,6 +1291,7 @@
path += ptr.asPath();
execute(consumer,
form,
+ currentView,
path,
localJXPathContext,
startRepeat.next,
@@ -1326,6 +1325,7 @@
path += startElement.attributes.getValue(REF);
execute(consumer,
form,
+ currentView,
path,
localJXPathContext,
startGroup.next,
@@ -1377,6 +1377,7 @@
path += ptr.asPath();
execute(consumer,
form,
+ currentView,
ptr.asPath(),
localJXPathContext,
startItemSet.next,
@@ -1452,14 +1453,14 @@
} else if (ev instanceof StartForm) {
StartForm startForm = (StartForm)ev;
StartElement startElement = startForm.startElement;
- currentView = startElement.attributes.getValue(VIEW);
+ String view = startElement.attributes.getValue(VIEW);
String id = startElement.attributes.getValue(ID);
Form newForm = Form.lookup(objectModel, id);
consumer.startElement(startElement.namespaceURI,
startElement.localName,
startElement.raw,
startElement.attributes);
- execute(consumer, newForm, contextPath,
+ execute(consumer, newForm, view, contextPath,
jxpathContextFactory.newContext(null,
newForm.getModel()),
startForm.next, startForm.endForm);
@@ -1488,15 +1489,28 @@
if (BACK.equals(cont)) {
level = 3;
}
- String kontId = kont.getContinuation(level).getId();
+ WebContinuation wk = kont;
+ for (int i = 0; i < level; i++) {
+ wk = wk.getParentContinuation();
+ if (wk == null) {
+ throw new SAXParseException("No such
continuation",
+ ev.location,
+ null);
+ }
+ }
+ String kontId = wk.getId();
AttributesImpl newAttrs =
new AttributesImpl(startElement.attributes);
int i = newAttrs.getIndex(ID);
+ String phase = attrs.getValue(PHASE);
+ if (phase == null) {
+ phase = currentView;
+ }
if (i >= 0) {
- newAttrs.setValue(i, kontId + ":" + id);
+ newAttrs.setValue(i, kontId + ":" + phase + ":" +id);
} else {
newAttrs.addAttribute("", ID, ID, "CDATA",
- kontId + ":" + id);
+ kontId + ":" + phase + ":" +
id);
}
attrs = newAttrs;
}
1.2 +4 -6
cocoon-2.1/src/scratchpad/webapp/samples/jxforms/flow/feedbackWizard.js
Index: feedbackWizard.js
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/jxforms/flow/feedbackWizard.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- feedbackWizard.js 27 Apr 2003 01:57:04 -0000 1.1
+++ feedbackWizard.js 27 Apr 2003 22:13:36 -0000 1.2
@@ -69,8 +69,7 @@
form.setModel(bean);
- form.sendView("userIdentity",
- "view/userIdentity.xml",
+ form.sendView("view/userIdentity.xml",
function(form) {
var bean = form.getModel();
print("I can also do validation in JavaScript");
@@ -82,8 +81,7 @@
});
print("handling user identity");
- form.sendView("deployment",
- "view/deployment.xml",
+ form.sendView("view/deployment.xml",
function(form) {
var bean = form.getModel();
print("I can also do validation in JavaScript");
@@ -93,10 +91,10 @@
});
print("handling deployment");
- form.sendView("system", "view/system.xml");
+ form.sendView("view/system.xml");
print("handling system");
- form.sendView("confirm", "view/confirm.xml");
+ form.sendView("view/confirm.xml");
print("handling confirm");
form.finish("view/end.xml");
1.2 +1 -1
cocoon-2.1/src/scratchpad/webapp/samples/jxforms/view/userIdentity.xml
Index: userIdentity.xml
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/jxforms/view/userIdentity.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- userIdentity.xml 27 Apr 2003 01:57:05 -0000 1.1
+++ userIdentity.xml 27 Apr 2003 22:13:36 -0000 1.2
@@ -77,7 +77,7 @@
<xf:hidden ref="hidden">
<xf:value>true</xf:value>
</xf:hidden>
- <xf:submit id="next" continuation="forward" class="button">
+ <xf:submit id="next" phase="userIdentity" continuation="forward"
class="button">
<xf:label>Next</xf:label>
<xf:hint>Go to next page</xf:hint>
</xf:submit>