A document has been updated:

http://cocoon.zones.apache.org/daisy/documentation/487.html

Document ID: 487
Branch: main
Language: default
Name: Cocoon Forms: Datatypes (unchanged)
Document Type: Cocoon Document (unchanged)
Updated on: 10/23/05 1:48:22 PM
Updated by: Bruno Dumon

A new version has been created, state: publish

Parts
=====
Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name:  (unchanged)
Size: 7873 bytes (previous version: 13301 bytes)
Content diff:
(38 equal lines skipped)
    Any further content of the fd:convertor element is specific to the convertor
    implementation and will be documented in a seperate section.</p>
    
--- <h2>Selection lists (default implementation)</h2>
--- 
--- <p>Widgets that have a datatype can also have a selection list. Since 
selection
--- lists are associated with datatypes, we discuss them here. The selection 
list
--- can be defined inline or read from an external source. Example of inline
--- declaration:</p>
--- 
--- <pre>&lt;fd:datatype base="long"/&gt;
--- &lt;fd:selection-list&gt;
---   &lt;fd:item value="1"/&gt;
---   &lt;fd:item value="2"/&gt;
---   &lt;fd:item value="3"&gt;
---     &lt;fd:label&gt;three&lt;/fd:label&gt;
---   &lt;/fd:item&gt;
---   &lt;fd:item value="4"/&gt;
---   &lt;fd:item value="5"/&gt;
--- &lt;/fd:selection-list&gt;</pre>
--- 
--- <p>Each item in the selection-list can have a value (specified in the value
--- attribute) and optionally a label (specified in the fd:label element). If no
--- label is specified, the value is used as label. The fd:label element can 
contain
--- mixed content.</p>
--- 
--- <p>To set a default selection, just set the value of the widget containing 
the
--- selection list.</p>
--- 
--- <p>Example of getting a selection list from an external source:</p>
--- 
--- <pre>&lt;fd:datatype base="string"/&gt;
--- &lt;fd:selection-list src="cocoon:/mychoices.xml"/&gt;</pre>
--- 
--- <p>All Cocoon-supported protocols can be used. The format of the XML 
produced by
--- the source should be the same as in case of inline specification of the
--- selection list, thus the root element should be a fd:selection-list 
element.</p>
--- 
--- <p>By default, the selection list will be retrieved form the source once, 
and
--- then become part of the form definition, just like when you would have 
defined
--- it inline. This has the consequence that if the XML produced by the source
--- changes, you won't see the selection list changed. If you'd like CForms to
--- retrieve the content of the selection list each time it needs it, add an
--- attribute called "dynamic" with value "true", for example:</p>
--- 
--- <pre>&lt;fd:datatype base="string"/&gt;
--- &lt;fd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/&gt;</pre>
--- 
--- <p>If the datatype is different from string, CForms will need to convert the
--- string values that appear in the selection list to their object equivalent. 
This
--- conversion is normally done using the same convertor as the datatype in 
which
--- the selection list appears, but you can also specify a different one. 
Here's an
--- example for a date selection list:</p>
--- 
--- <pre>&lt;fd:datatype base="date"/&gt;
--- &lt;fd:selection-list&gt;
---   &lt;fd:convertor type="formatting"&gt;
---     &lt;fd:patterns&gt;
---       &lt;fd:pattern&gt;yyyyMMdd&lt;/fd:pattern&gt;
---     &lt;/fd:patterns&gt;
---   &lt;/fd:convertor&gt;
---   &lt;fd:item value="13020711"/&gt;
---   &lt;fd:item value="19120623"/&gt;
---   &lt;fd:item value="19690721"/&gt;
---   &lt;fd:item value="19700506"/&gt;
---   &lt;fd:item value="19781014"/&gt;
---   &lt;fd:item value="20010911"/&gt;
--- &lt;/fd:selection-list&gt;</pre>
--- 
--- <p>If there is a fd:convertor element, it should always be the first child
--- element of the fd:selection-list element. This works of course also for
--- selection lists retrieved from external sources.</p>
--- 
--- <p>Selection list implementations are pluggable. Everything said until now
--- applies to the default selection list implementation. An alternative
--- implementation can be specified by using a <strong>type</strong> attribute 
on
--- the fd:selection-list element. The sections below describe the alternative
--- implementations currently available.</p>
--- 
--- <h2>Selection lists: flow-jxpath implementation</h2>
--- 
--- <p>See the javadoc of the
--- <a 
href="http://cvs.apache.org/viewcvs.cgi/*checkout*/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java?rev=HEAD";>FlowJXPathSelectionListBuilder</a>
--- class for now.</p>
--- 
--- <p>Example:</p>
--- 
--- <p>In flowscript:</p>
--- 
--- <pre>var data = new Object();
--- 
--- data.cityList = new Array(2);
--- data.cityList[0] = {value:"AL", label:"Alabama"};
--- data.cityList[1] = {value:"AK", label:"Alaska"};
--- 
--- form.showForm("flow/myform.form", data);</pre>
--- 
--- <p>and the corresponding selection list definition:</p>
--- 
--- <pre>&lt;fd:selection-list type="flow-jxpath" list-path="cityList"
---                    value-path="value" label-path="label" /&gt;</pre>
--- 
--- <p>Hint: the label can be any kind of object, its toString() method will be
--- called to get the string to be displayed. In case the object supplied as 
label
--- implements the XMLizable interface, its toSAX method will be called 
instead. One
--- practical application of this is using i18n labels:</p>
--- 
--- <pre>importClass (Packages.org.apache.cocoon.forms.util.I18nMessage);
--- ...
--- mylist[0] = {value: "x", label: new I18nMessage("myI18nKey") };</pre>
--- 
--- <h2>Selection lists: enum implementation</h2>
--- 
--- <p>This type of selection list outputs a list of items corresponding to the
--- possible instances of an enumerated type (see below).</p>
--- 
--- <p>Example:</p>
--- 
--- <pre>&lt;fd:selection-list type="enum" class="com.example.Sex"/&gt;</pre>
--- 
--- <p>outputs:</p>
--- 
--- <pre>&lt;fi:selection-list&gt;
---   &lt;fi:item value=""/&gt;
---   &lt;fi:item value="com.example.Sex.MALE"&gt;
---     &lt;fi:label&gt;
---       &lt;i18n:text&gt;com.example.Sex.MALE&lt;/i18n:text&gt;
---     &lt;/fi:label&gt;
---   &lt;/fi:item&gt;
---   &lt;fi:item value="com.example.Sex.FEMALE"&gt;
---     &lt;fi:label&gt;
---       &lt;i18n:text&gt;com.example.Sex.FEMALE&lt;/i18n:text&gt;
---     &lt;/fi:label&gt;
---   &lt;/fi:item&gt;
--- &lt;/fi:selection-list&gt;</pre>
--- 
--- <p>If you don't want an initial null value, add a
--- <strong>nullable="false"</strong> attribute to the
--- <strong>fd:selection-list</strong> element. This applies only to
--- <strong>enum</strong> type selection lists.</p>
--- 
    <h1>Available datatypes</h1>
    
    <table>
(235 equal lines skipped)


Fields
======
no changes

Links
=====
no changes

Custom Fields
=============
no changes

Collections
===========
no changes