vgritsenko 2004/02/28 22:18:29
Modified: src/blocks/woody/samples/forms form1.xml form1_template.xml
src/blocks/woody/samples/v2 form1.xml
Added: src/blocks/woody/samples/aggregate binding-combine.xml
binding-split.xml example.js form.xml sitemap.xmap
template-combine.xml template-split.xml
Log:
Add aggregate field sample
Revision Changes Path
1.1
cocoon-2.1/src/blocks/woody/samples/aggregate/binding-combine.xml
Index: binding-combine.xml
===================================================================
<?xml version="1.0"?>
<!--+
| CForms aggregate sample binding. Loads/stores values of two aggregate
| fields as multiple parts.
|
| CVS $Id: binding-combine.xml,v 1.1 2004/02/29 06:18:28 vgritsenko Exp $
+-->
<wb:context xmlns:wb="http://apache.org/cocoon/woody/binding/1.0"
path="/">
<wb:aggregate id="phone" path=".">
<wb:value id="part1" path="part1"/>
<wb:value id="part2" path="part2"/>
<wb:value id="part3" path="part3"/>
<wb:value id="part4" path="part4"/>
</wb:aggregate>
<wb:aggregate id="date" path=".">
<wb:value id="day" path="day"/>
<wb:value id="month" path="month"/>
<wb:value id="year" path="year"/>
</wb:aggregate>
</wb:context>
1.1
cocoon-2.1/src/blocks/woody/samples/aggregate/binding-split.xml
Index: binding-split.xml
===================================================================
<?xml version="1.0"?>
<!--+
| CForms aggregate sample binding. Loads/stores values of two aggregate
| fields as two values.
|
| CVS $Id: binding-split.xml,v 1.1 2004/02/29 06:18:28 vgritsenko Exp $
+-->
<wb:context xmlns:wb="http://apache.org/cocoon/woody/binding/1.0"
path="/">
<wb:value id="phone" path="phone"/>
<wb:value id="date" path="date"/>
</wb:context>
1.1 cocoon-2.1/src/blocks/woody/samples/aggregate/example.js
Index: example.js
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody2.js");
Bean.prototype.date;
Bean.prototype.phone;
function Bean () {
};
function example() {
var bean = new Bean();
var form = new Form("form.xml");
var template = "combine";
while (true) {
form.createBinding("binding-" + template + ".xml");
// java.lang.System.out.println("Loading. Date: " + bean.date + ",
Day: " + bean.day + ", Month: " + bean.month + ", Year: " + bean.year);
form.load(bean);
form.showForm(template + "-display-pipeline", bean);
form.save(bean);
// java.lang.System.out.println("Saved. Date: " + bean.date + ", Day:
" + bean.day + ", Month: " + bean.month + ", Year: " + bean.year);
if (form.submitId == "switch") {
if (template == "combine") {
template = "split";
} else {
template = "combine";
}
// Preserve values after switch
form.createBinding("binding-" + template + ".xml");
form.save(bean);
}
}
}
1.1 cocoon-2.1/src/blocks/woody/samples/aggregate/form.xml
Index: form.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--+
| CForms aggegate sample form definition file.
|
| CVS $Id: form.xml,v 1.1 2004/02/29 06:18:28 vgritsenko Exp $
+-->
<wd:form xmlns:wd="http://apache.org/cocoon/woody/definition/1.0">
<wd:widgets>
<wd:aggregatefield id="phone" required="true">
<wd:label>
Enter Phone Number
<br/><small>(Format is: 999-999-9999x9999)
<br/>Extension number is optional.</small>
</wd:label>
<wd:datatype base="string"/>
<wd:split pattern="([0-9]{3})-([0-9]{3})-([0-9]{4})(x([0-9]{1,4}))?">
<wd:map group="1" field="part1"/>
<wd:map group="2" field="part2"/>
<wd:map group="3" field="part3"/>
<wd:map group="5" field="part4"/>
<wd:failmessage>Not a valid phone number.</wd:failmessage>
</wd:split>
<wd:combine expression='Concat(part1, "-", part2, "-", part3,
If(IsNull(part4), "", Concat("x", part4))) )'/>
<wd:widgets>
<wd:field id="part1" required="true">
<wd:label>
Enter Phone (Part1)
<br/><small>(Format is: 999)</small>
</wd:label>
<wd:datatype base="string"/>
</wd:field>
<wd:field id="part2" required="true">
<wd:label>
Enter Phone (Part2)
<br/><small>(Format is: 999)</small>
</wd:label>
<wd:datatype base="string"/>
</wd:field>
<wd:field id="part3" required="true">
<wd:label>
Enter Phone (Part3)
<br/><small>(Format is: 9999)</small>
</wd:label>
<wd:datatype base="string"/>
</wd:field>
<wd:field id="part4">
<wd:label>
Enter Phone (Part4)
<br/><small>(Format is: 9999)</small>
</wd:label>
<wd:datatype base="string"/>
</wd:field>
</wd:widgets>
</wd:aggregatefield>
<wd:aggregatefield id="date" required="true">
<wd:label>
Enter Date
<br/><small>(Format is: dd/MM/yyyy)
<br/>Year should be between 1990 and 2010. Day should be between 1 to
15</small>
</wd:label>
<wd:datatype base="date">
<wd:convertor>
<wd:patterns>
<wd:pattern>dd/MM/yyyy</wd:pattern>
</wd:patterns>
</wd:convertor>
<wd:validation>
<wd:range min="Date(1990, 1, 1)" max="Date(2010, 12, 31)">
<wd:failmessage>Enter date in 1990 to 2010 year</wd:failmessage>
</wd:range>
</wd:validation>
</wd:datatype>
<wd:split pattern="([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})">
<wd:map group="1" field="day"/>
<wd:map group="2" field="month"/>
<wd:map group="3" field="year"/>
<wd:failmessage>Not a valid date.</wd:failmessage>
</wd:split>
<wd:combine expression='Date(year, month, day)'/>
<wd:widgets>
<wd:field id="day" required="true">
<wd:datatype base="integer"/>
<wd:label>
Enter Day
<br/><small>(Day should be between 1 to 15)</small>
</wd:label>
<wd:validation>
<wd:range min="1" max="15">
<wd:failmessage>Enter date between 1st and 15th day of the
month.</wd:failmessage>
</wd:range>
</wd:validation>
</wd:field>
<wd:field id="month" required="true">
<wd:label>
Enter Month
<br/><small>(Month should be between 1 to 12)</small>
</wd:label>
<wd:datatype base="integer"/>
<wd:selection-list>
<wd:item value="">
<wd:label>Select Month</wd:label>
</wd:item>
<wd:item value="1">
<wd:label>January</wd:label>
</wd:item>
<wd:item value="2">
<wd:label>February</wd:label>
</wd:item>
<wd:item value="3">
<wd:label>March</wd:label>
</wd:item>
<wd:item value="4">
<wd:label>April</wd:label>
</wd:item>
<wd:item value="5">
<wd:label>May</wd:label>
</wd:item>
<wd:item value="6">
<wd:label>June</wd:label>
</wd:item>
<wd:item value="7">
<wd:label>July</wd:label>
</wd:item>
<wd:item value="8">
<wd:label>August</wd:label>
</wd:item>
<wd:item value="9">
<wd:label>September</wd:label>
</wd:item>
<wd:item value="10">
<wd:label>October</wd:label>
</wd:item>
<wd:item value="11">
<wd:label>November</wd:label>
</wd:item>
<wd:item value="12">
<wd:label>December</wd:label>
</wd:item>
</wd:selection-list>
</wd:field>
<wd:field id="year" required="true">
<wd:label>
Enter Year
<br/><small>(Year should be between 1990 to 2010)</small>
</wd:label>
<wd:datatype base="integer"/>
</wd:field>
</wd:widgets>
</wd:aggregatefield>
<wd:submit id="switch" action-command="switch" validate="false">
<wd:label>Switch</wd:label>
</wd:submit>
</wd:widgets>
</wd:form>
1.1
cocoon-2.1/src/blocks/woody/samples/aggregate/sitemap.xmap
Index: sitemap.xmap
===================================================================
<?xml version="1.0"?>
<!--+
| CForms aggegate sample sitemap.
|
| CVS $Id: sitemap.xmap,v 1.1 2004/02/29 06:18:28 vgritsenko Exp $
+-->
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:views>
<map:view name="content" from-label="content">
<map:serialize type="xml"/>
</map:view>
<map:view from-label="content" name="pretty-content">
<map:transform src="context://stylesheets/system/xml2html.xslt"/>
<map:serialize type="html"/>
</map:view>
<map:view name="links" from-position="last">
<map:serialize type="links"/>
</map:view>
</map:views>
<map:resources>
<map:resource name="simple-page2html">
<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="{file}"/>
<map:parameter name="remove" value="{../0}"/>
</map:transform>
</map:resource>
</map:resources>
<map:flow language="javascript">
<map:script src="example.js"/>
</map:flow>
<map:pipelines>
<map:pipeline>
<map:match pattern="example">
<map:call function="example"/>
</map:match>
<map:match pattern="*.continue">
<map:call continuation="{1}"/>
</map:match>
<map:match pattern="*-display-pipeline">
<!-- pipeline to show the form -->
<map:generate type="jx" src="template-{1}.xml"/>
<map:transform type="woody"/>
<map:call resource="simple-page2html">
<map:parameter name="file" value="{1}_template.xml"/>
</map:call>
<map:transform src="../resources/woody-samples-styling.xsl">
<map:parameter name="resources-uri" value="../resources"/>
</map:transform>
<map:serialize/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
1.1
cocoon-2.1/src/blocks/woody/samples/aggregate/template-combine.xml
Index: template-combine.xml
===================================================================
<?xml version="1.0"?>
<!--+
| CForms aggregate sample binding. Represent values of two aggregate
| fields as single input fields.
|
| CVS $Id: template-combine.xml,v 1.1 2004/02/29 06:18:28 vgritsenko Exp $
+-->
<page xmlns:wt="http://apache.org/cocoon/woody/template/1.0"
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<title>Aggregate Field: Combine</title>
<content>
<p>
On this form, you can enter phone and date, each as one field.
</p>
<wt:form-template action="${cocoon.continuation.id}.continue"
method="POST">
<table align="center">
<tr>
<th style="border-bottom: solid 1px black;">Explanation</th>
<th style="border-bottom: solid 1px black;">Form</th>
<th style="border-bottom: solid 1px black;">Data Model</th>
</tr>
<tr>
<td>
<p>
When you click submit, following happens:
<ul>
<li>Input values are validated</li>
<li>Input values are split onto parts</li>
<li>Each part value is validated</li>
<li>Each part value saved into the backend data model</li>
</ul>
</p>
<p>
Switch to another aggregation example:
</p>
<wt:widget id="switch"/>
</td>
<td>
<wi:group>
<wi:styling layout="columns"/>
<wi:items>
<wt:widget id="phone"/>
<wt:widget id="date"/>
</wi:items>
</wi:group>
<input type="submit" value="Submit"/>
</td>
<td>
<table cellpadding="3">
<tr>
<td>Phone, part 1</td><th>#{part1}</th>
</tr>
<tr>
<td>Phone, part 2</td><th>#{part2}</th>
</tr>
<tr>
<td>Phone, part 3</td><th>#{part3}</th>
</tr>
<tr>
<td>Phone, part 4</td><th>#{part4}</th>
</tr>
<tr>
<td>Date, Day</td><th>#{day}</th>
</tr>
<tr>
<td>Date, Month</td><th>#{month}</th>
</tr>
<tr>
<td>Date, Year</td><th>#{year}</th>
</tr>
</table>
</td>
</tr>
</table>
</wt:form-template>
</content>
</page>
1.1
cocoon-2.1/src/blocks/woody/samples/aggregate/template-split.xml
Index: template-split.xml
===================================================================
<?xml version="1.0"?>
<!--+
| CForms aggregate sample binding. Represent values of two aggregate
| fields as multiple input fields.
|
| CVS $Id: template-split.xml,v 1.1 2004/02/29 06:18:28 vgritsenko Exp $
+-->
<page xmlns:wt="http://apache.org/cocoon/woody/template/1.0"
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<title>Aggregate Field: Split</title>
<content>
<p>
On this form, you can enter phone and date, each as splitted on several
fields.
</p>
<wt:form-template action="${cocoon.continuation.id}.continue"
method="POST">
<table align="center">
<tr>
<th style="border-bottom: solid 1px black;">Explanation</th>
<th style="border-bottom: solid 1px black;">Form</th>
<th style="border-bottom: solid 1px black;">Data Model</th>
</tr>
<tr>
<td>
<p>
When you click submit, following happens:
<ul>
<li>Input values are validated</li>
<li>Input values are aggregated into one value</li>
<li>Each value is validated</li>
<li>Each value saved into the backend data model</li>
</ul>
</p>
<p>
Switch to another aggregation example:
</p>
<wt:widget id="switch"/>
</td>
<td>
<wi:group>
<wi:styling layout="columns"/>
<wi:items>
<wt:aggregate-widget id="phone">
<wt:widget id="part1"/>
<wt:widget id="part2"/>
<wt:widget id="part3"/>
<wt:widget id="part4"/>
</wt:aggregate-widget>
<wt:aggregate-widget id="date">
<wt:widget id="day"/>
<wt:widget id="month"/>
<wt:widget id="year"/>
</wt:aggregate-widget>
</wi:items>
</wi:group>
<input type="submit" value="Submit"/>
</td>
<td>
<table cellpadding="3">
<tr>
<td>Phone</td><th>#{phone}</th>
</tr>
<tr>
<td>Date</td><th>#{date}</th>
</tr>
</table>
</td>
</tr>
</table>
</wt:form-template>
</content>
</page>
1.21 +4 -2 cocoon-2.1/src/blocks/woody/samples/forms/form1.xml
Index: form1.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/forms/form1.xml,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- form1.xml 4 Feb 2004 23:30:34 -0000 1.20
+++ form1.xml 29 Feb 2004 06:18:28 -0000 1.21
@@ -122,8 +122,10 @@
<wd:aggregatefield id="visa" required="true">
<wd:label>Enter your (16-digit) visa number (without spaces)
<br/>Your credit card will be billed.
- <br/><small>Valid test number is: 4111111111111111</small></wd:label>
+ <br/><small>Valid test number is: 4111111111111111</small>
+ </wd:label>
<wd:help>Use a fake number if <a
href="http://cocoon.apache.org">Cocoon</a> is not running on your local
computer</wd:help>
+ <wd:datatype base="string"/>
<wd:split pattern="([0-9]{4})([0-9]{4})([0-9]{4})([0-9]{4})">
<wd:map group="1" field="part1"/>
<wd:map group="2" field="part2"/>
1.10 +3 -2
cocoon-2.1/src/blocks/woody/samples/forms/form1_template.xml
Index: form1_template.xml
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/woody/samples/forms/form1_template.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- form1_template.xml 19 Nov 2003 18:19:12 -0000 1.9
+++ form1_template.xml 29 Feb 2004 06:18:28 -0000 1.10
@@ -6,8 +6,9 @@
<content>
<wt:form-template action="#{$continuation/id}.continue" method="POST">
<table align="center">
- <tr><td>
-
+ <tr>
+ <td>
+
<!-- group with tabs. Each of the children of <items> will
constitute a tab -->
<wi:group>
<wi:styling type="choice"/>
1.3 +4 -2 cocoon-2.1/src/blocks/woody/samples/v2/form1.xml
Index: form1.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/v2/form1.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- form1.xml 29 Feb 2004 05:58:11 -0000 1.2
+++ form1.xml 29 Feb 2004 06:18:29 -0000 1.3
@@ -112,8 +112,10 @@
<wd:aggregatefield id="visa" required="true">
<wd:label>Enter your (16-digit) visa number (without spaces)
<br/>Your credit card will be billed.
- <br/><small>Valid test number is: 4111111111111111</small></wd:label>
+ <br/><small>Valid test number is: 4111111111111111</small>
+ </wd:label>
<wd:help>Use a fake number if <a
href="http://cocoon.apache.org">Cocoon</a> is not running on your local
computer</wd:help>
+ <wd:datatype base="string"/>
<wd:split pattern="([0-9]{4})([0-9]{4})([0-9]{4})([0-9]{4})">
<wd:map group="1" field="part1"/>
<wd:map group="2" field="part2"/>