bruno 2003/11/14 01:47:27
Modified: src/blocks/woody/samples sitemap.xmap welcome.xml
Added: src/blocks/woody/samples/flow customvalidationdemo.js
src/blocks/woody/samples/forms customvalidationdemo_form.xml
customvalidationdemo_template.xml
Log:
Added new sample illustrating the use of a custom validation function,
the messages widget, and wi:validation-errors
Revision Changes Path
1.1
cocoon-2.1/src/blocks/woody/samples/flow/customvalidationdemo.js
Index: customvalidationdemo.js
===================================================================
cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody2.js");
function customValidationDemo() {
var form = new Form("forms/customvalidationdemo_form.xml");
// the line below is the crucial piece for this demo: assigning
// a function to do extra validation
form.validator = myValidator;
form.showForm("customvalidationdemo-display-pipeline");
}
function myValidator(form) {
// Add an error message to specific widgets as follows:
var validationError = new
Packages.org.apache.cocoon.woody.datatype.ValidationError("This is so wrong.");
form.getWidget("number1").setValidationError(validationError);
form.getWidget("number2").setValidationError(validationError);
// Add some other messages to the 'messages' widget
form.getWidget("messages").addMessage("You'll never be able to enter
valid data!");
form.getWidget("messages").addMessage("Ha ha ha!");
// to add i18n messages, do something like:
// var i18nMessage = new
Packages.org.apache.cocoon.woody.util.I18nMessage("key");
// form.getWidget("messages").addMessage(i18nMessage);
// The I18nMessage class supports a variety of other constructors to do
more
// powerful things, be sure to check them out.
// Note that instead of doing all the above here in Javascript,
// you can also delegate this work to a Java class (or Avalon component).
// always return false, so that the form will never be valid
return false;
}
1.1
cocoon-2.1/src/blocks/woody/samples/forms/customvalidationdemo_form.xml
Index: customvalidationdemo_form.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- form used to illustrate programmatic changing of listbox content. -->
<wd:form
xmlns:wd="http://apache.org/cocoon/woody/definition/1.0">
<wd:widgets>
<wd:messages id="messages">
<wd:label>Here are some messages for you</wd:label>
</wd:messages>
<wd:field id="number1">
<wd:label>First number</wd:label>
<wd:datatype base="long"/>
</wd:field>
<wd:field id="number2">
<wd:label>Second number</wd:label>
<wd:datatype base="long"/>
</wd:field>
</wd:widgets>
</wd:form>
1.1
cocoon-2.1/src/blocks/woody/samples/forms/customvalidationdemo_template.xml
Index: customvalidationdemo_template.xml
===================================================================
<?xml version="1.0"?>
<page xmlns:wt="http://apache.org/cocoon/woody/template/1.0"
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0">
<title>Custom validation sample</title>
<content>
<wt:form-template action="#{$continuation/id}.continue" method="POST">
<p>This form illustrates a number of validation related features.</p>
<p>First of all, if there are any validation errors attached to widgets
in the form, you can have them all displayed at one location by using
the <wi:validation-errors/> tag, as we have done here: (you'll
only see something after submitting the form).</p>
<wi:validation-errors/>
<p>Below, a messages widget is inserted, which allows to display
messages
such as validation errors that are not related to any widget in
particular: (you'll only see something after submitting the form)</p>
<wt:widget id="messages"/>
<br/>
<br/>
<wt:widget-label id="number1"/>:
<wt:widget id="number1"/>
<br/>
<wt:widget-label id="number2"/>:
<wt:widget id="number2"/>
<br/>
<br/>
<input type="submit"/>
</wt:form-template>
</content>
</page>
1.28 +27 -0 cocoon-2.1/src/blocks/woody/samples/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/sitemap.xmap,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- sitemap.xmap 13 Nov 2003 14:57:05 -0000 1.27
+++ sitemap.xmap 14 Nov 2003 09:47:27 -0000 1.28
@@ -56,6 +56,7 @@
<map:script src="flow/binding_example.js"/>
<map:script src="flow/upload_example.js"/>
<map:script src="flow/registration.js"/>
+ <map:script src="flow/customvalidationdemo.js"/>
</map:flow>
<map:pipelines>
@@ -428,6 +429,32 @@
<map:parameter name="file"
value="forms/countryselector_success.xsp"/>
<map:parameter name="remove" value="{0}"/>
</map:transform>
+ <map:serialize/>
+ </map:match>
+
+ <!--
+ | Custom validation example
+ -->
+
+ <map:match pattern="customvalidationdemo">
+ <map:call function="customValidationDemo"/>
+ </map:match>
+
+ <map:match pattern="customvalidationdemo-display-pipeline">
+ <!-- pipeline to show the form -->
+ <map:generate src="forms/customvalidationdemo_template.xml"/>
+ <map:transform type="woody"/>
+ <map:transform type="i18n">
+ <map:parameter name="locale" value="en-US"/>
+ </map:transform>
+ <map:transform
src="context://samples/common/style/xsl/html/simple-page2html.xsl">
+ <map:parameter name="contextPath" value="{request:contextPath}"/>
+ <map:parameter name="servletPath" value="{request:servletPath}"/>
+ <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
+ <map:parameter name="file" value="forms/form1_template.xml"/>
+ <map:parameter name="remove" value="{0}"/>
+ </map:transform>
+ <map:transform src="resources/woody-samples-styling.xsl"/>
<map:serialize/>
</map:match>
1.9 +1 -0 cocoon-2.1/src/blocks/woody/samples/welcome.xml
Index: welcome.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/welcome.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- welcome.xml 13 Nov 2003 14:57:05 -0000 1.8
+++ welcome.xml 14 Nov 2003 09:47:27 -0000 1.9
@@ -19,6 +19,7 @@
<sample name="Registration" href="registration">A simple registration
form.</sample>
<sample name="Car selector" href="carselector">Illustrates
programmatically changing selectionlists.</sample>
<sample name="Upload" href="upload">Shows an upload widget used with
Flowscript</sample>
+ <sample name="Custom validation" href="customvalidationdemo">Shows custom
validation and messages widget.</sample>
</group>
<group name="Binding Samples">