blob: 966e814be51fd33acb739370534a84988d7bff52 [file] [log] [blame]
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
- Binding template between
- * form_data file (backend)
- * and form_model file
-->
<fb:context
xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
path="/data/wrapper/context" >
<fb:context path="info">
<!-- the email value will not be saved because of the @direction="load" -->
<fb:value id="email" path="email" direction="load"/>
<!-- jxpath binds to nodes as well as to attributes -->
<fb:value id="number" path="number/@value">
<!-- for non-string datatypes, a convertor must be specified. These are
the same convertors as can be used in form definitions, but require an
extra datatype attribute. Here we use the default convertor for longs. -->
<fd:convertor datatype="integer"/>
</fb:value>
<fb:value id="choose" path="choose/@value">
<fd:convertor datatype="boolean"/>
</fb:value>
<!-- one entry field in the client maps through aggregate fields -->
<fb:aggregate id="phone" path="phone" >
<!-- to multiple fields in the XML file -->
<fb:value id="number" path="number" />
<fb:value id="zone" path="zone" />
<fb:value id="cntr" path="@cntr" />
</fb:aggregate>
</fb:context>
<fb:value id="ipaddress" path="ipaddress">
<fb:on-update>
<!-- if the value has changed, the attribute will be set -->
<fb:set-attribute name="changed" value="true"/>
</fb:on-update>
</fb:value>
<fb:value id="birthday" path="birthday">
<fd:convertor datatype="date" type="formatting">
<fd:patterns>
<fd:pattern>yyyy-MM-dd</fd:pattern>
</fd:patterns>
</fd:convertor>
</fb:value>
<fb:multi-value id="drinks" parent-path="drinks" row-path="drink"/>
<!--
- Repeater requires unique identification mechanism of the row-nodes.
- (it is of course possible to implement other binding strategies)
-
- Important NOTE: When adding rows, the row-path is used inside
- jxpath-createPath context, as a consequence it cannot have dependent
- children or predicates.
-->
<fb:repeater id="contacts"
parent-path="contacts"
row-path="contact">
<fb:identity>
<fb:value id="id" path="@id" direction="load">
<!-- optional convertor to use for mapping the unique id -->
<fd:convertor datatype="long" />
</fb:value>
</fb:identity>
<fb:on-bind>
<!-- executed on updates AND right after the insert -->
<fb:javascript id="id" path="@id" direction="save">
<fb:save-form>
var appValue = jxpathPointer.getValue();
if (appValue == '') {
var precSiblId = jxpathContext.getValue("../preceding-sibling::contact/@id");
var newId = Number(precSiblId) + 1
jxpathPointer.setValue(newId.toFixed(0));
}
</fb:save-form>
</fb:javascript>
<fb:value id="firstname" path="firstname" />
<fb:value id="middleInitial" path="firstname/@middleInitial" />
<fb:value id="lastname" path="lastname" />
<fb:value id="phone" path="phone/@nr" />
<fb:value id="email" path="email" />
<fb:value id="preferred" path="preferred"/>
</fb:on-bind>
<fb:on-delete-row>
<!-- choose one of these to test -->
<!--
<fb:set-attribute name="row-state" value="deleted" />
-->
<fb:delete-node />
</fb:on-delete-row>
<fb:on-insert-row>
<!-- The insert-node element contains a piece of template XML to be
inserted for new rows. Alternatively, you could also add a "src"
attribute on the insert-node element pointing to an external source
to retrieve the template from. -->
<fb:insert-node>
<!-- template inserted by the binding for new rows (mapping new nodes) -->
<contact id="" row-state="new">
<firstname/><lastname/><phone nr=""/><email/>
</contact>
</fb:insert-node>
</fb:on-insert-row>
</fb:repeater>
</fb:context>