cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@cocoon.apache.org
Subject [Cocoon Wiki] Updated: WoodyDatatypeReference
Date Mon, 19 Jul 2004 18:22:35 GMT
   Date: 2004-07-19T11:22:35
   Editor: StephanNiedermeier <nospam@nono.no>
   Wiki: Cocoon Wiki
   Page: WoodyDatatypeReference
   URL: http://wiki.apache.org/cocoon/WoodyDatatypeReference

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -2,8 +2,8 @@
 
 In its most basic form a datatype is declared as follows:
 
-{{{
-<wd:datatype base="...">
+{{{
+<wd:datatype base="...">
 }}}
 
 The '''base''' attribute refers to one of the built-in datatypes such as string or long.
@@ -16,14 +16,14 @@
 == Convertors ==
 
 A datatype also needs a convertor. The purpose of a convertor is to convert between string
and object representations of values. There is always a default convertor, but you change
or configure that using the '''wd:convertor''' element. Here's an example for dates:
-{{{
-<wd:datatype base="date">
-  <wd:convertor type="formatting">
-    <wd:patterns>
-      <wd:pattern>dd/MM/yyyy</wd:pattern>
-    </wd:patterns>
-  </wd:convertor>
-</wd:datatype>
+{{{
+<wd:datatype base="date">
+  <wd:convertor type="formatting">
+    <wd:patterns>
+      <wd:pattern>dd/MM/yyyy</wd:pattern>
+    </wd:patterns>
+  </wd:convertor>
+</wd:datatype>
 }}}
 
 The '''type''' attribute on the wd:convertor element is optional, if not specified the default
one will be used (configured in the cocoon.xconf). Any further content of the wd:convertor
element is specific to the convertor implementation and will be documented in a seperate section.
@@ -32,17 +32,17 @@
 
 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:
 
-{{{
-<wd:datatype base="long"/>
-<wd:selection-list>
-  <wd:item value="1"/>
-  <wd:item value="2"/>
-  <wd:item value="3">
-    <wd:label>three</wd:label>
-  </wd:item>
-  <wd:item value="4"/>
-  <wd:item value="5"/>
-</wd:selection-list>
+{{{
+<wd:datatype base="long"/>
+<wd:selection-list>
+  <wd:item value="1"/>
+  <wd:item value="2"/>
+  <wd:item value="3">
+    <wd:label>three</wd:label>
+  </wd:item>
+  <wd:item value="4"/>
+  <wd:item value="5"/>
+</wd:selection-list>
 }}}
 
 Each item in the selection-list can have a value (specified in the value attribute) and optionally
a label (specified in the wd:label element). If no label is specified, the value is used as
label. The wd:label element can contain mixed content.
@@ -50,35 +50,35 @@
 To set a default selection, just set the value of the widget containing the selection list.
 
 Example of getting a selection list from an external source:
-{{{
-<wd:datatype base="string"/>
-<wd:selection-list src="cocoon:/mychoices.xml"/>
+{{{
+<wd:datatype base="string"/>
+<wd:selection-list src="cocoon:/mychoices.xml"/>
 }}}
 
 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 wd:selection-list element.
 
 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 Woody to retrieve the content of the selection list each time it needs it, add
an attribute called "dynamic" with value "true", for example:
-{{{
-<wd:datatype base="string"/>
-<wd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
+{{{
+<wd:datatype base="string"/>
+<wd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
 }}}
 
 If the datatype is different from string, Woody 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:
-{{{
-<wd:datatype base="date"/>
-<wd:selection-list>
-  <wd:convertor type="formatting">
-    <wd:patterns>
-      <wd:pattern>yyyyMMdd</wd:pattern>
-    </wd:patterns>
-  </wd:convertor>
-  <wd:item value="13020711"/>
-  <wd:item value="19120623"/>
-  <wd:item value="19690721"/>
-  <wd:item value="19700506"/>
-  <wd:item value="19781014"/>
-  <wd:item value="20010911"/>
-</wd:selection-list>
+{{{
+<wd:datatype base="date"/>
+<wd:selection-list>
+  <wd:convertor type="formatting">
+    <wd:patterns>
+      <wd:pattern>yyyyMMdd</wd:pattern>
+    </wd:patterns>
+  </wd:convertor>
+  <wd:item value="13020711"/>
+  <wd:item value="19120623"/>
+  <wd:item value="19690721"/>
+  <wd:item value="19700506"/>
+  <wd:item value="19781014"/>
+  <wd:item value="20010911"/>
+</wd:selection-list>
 }}}
 
 If there is a wd:convertor element, it should always be the first child element of the wd:selection-list
element. This works of course also for selection lists retrieved from external sources.
@@ -92,20 +92,20 @@
 Example:
 
 In flowscript:
-{{{
-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);
+{{{
+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);
 }}}
 
 and the corresponding selection list definition:
 
-{{{
-<wd:selection-list type="flow-jxpath" list-path="cityList" value-path="value" label-path="label"
/>
+{{{
+<wd:selection-list type="flow-jxpath" list-path="cityList" value-path="value" label-path="label"
/>
 }}}
 
 == Selection lists: enum implementation ==
@@ -114,69 +114,69 @@
 
 Example:
 
-{{{
-<wd:selection-list type="enum" class="com.example.Sex"/>
+{{{
+<wd:selection-list type="enum" class="com.example.Sex"/>
 }}}
 
 outputs:
 
-{{{
-<wi:selection-list>
-  <wi:item value=""/>
-  <wi:item value="com.example.Sex.MALE">
-    <wi:label>
-      <i18n:text>com.example.Sex.MALE</i18n:text>
-    </wi:label>
-  </wi:item>
-  <wi:item value="com.example.Sex.FEMALE">
-    <wi:label>
-      <i18n:text>com.example.Sex.FEMALE</i18n:text>
-    </wi:label>
-  </wi:item>
-</wi:selection-list>
+{{{
+<wi:selection-list>
+  <wi:item value=""/>
+  <wi:item value="com.example.Sex.MALE">
+    <wi:label>
+      <i18n:text>com.example.Sex.MALE</i18n:text>
+    </wi:label>
+  </wi:item>
+  <wi:item value="com.example.Sex.FEMALE">
+    <wi:label>
+      <i18n:text>com.example.Sex.FEMALE</i18n:text>
+    </wi:label>
+  </wi:item>
+</wi:selection-list>
 }}}
 
 If you don't want an initial null value, add a '''nullable="false"''' attribute to the '''wd:selection-list'''
element. This applies only to '''enum''' type selection lists.
 
 = Available datatypes =
 
-||'''Woody Datatype'''||'''Java class'''||||Convertors
-||string||{{{java.lang.String}}}||Strings obviously don't support any convertors, since there's
no purpose in converting a string to a string.
-||decimal||{{{java.math.BigDecimal}}}||formatting (decimal), plain
-||integer||{{{java.lang.Integer}}}||similar as decimal datatype
-||long||{{{java.lang.Long}}}||similar as decimal datatype
-||date||{{{java.util.Date}}}||formatting (date), millis
-||enum||Enumerated type||enum
+||'''Woody Datatype'''||'''Java class'''||Convertors||
+||string||{{{java.lang.String}}}||Strings obviously don't support any convertors, since there's
no purpose in converting a string to a string.||
+||decimal||{{{java.math.BigDecimal}}}||formatting (decimal), plain||
+||integer||{{{java.lang.Integer}}}||similar as decimal datatype||
+||long||{{{java.lang.Long}}}||similar as decimal datatype||
+||date||{{{java.util.Date}}}||formatting (date), millis||
+||enum||Enumerated type||enum||
 
 == Enumerated datatypes ==
 
 The '''enum''' datatype is meant to be used with types implementing Joshua Bloch's [http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums
typesafe enum pattern].     The following is a possible implementation:
 
-{{{
-package com.example;
-
-public class Sex {
-
-    public static final Sex MALE = new Sex("M");
-    public static final Sex FEMALE = new Sex("F");
-    private String code;
-
-    private Sex(String code) { this.code = code; }
-}
+{{{
+package com.example;
+
+public class Sex {
+
+    public static final Sex MALE = new Sex("M");
+    public static final Sex FEMALE = new Sex("F");
+    private String code;
+
+    private Sex(String code) { this.code = code; }
+}
 }}}
 
 The following snippet shows the usage of this type:
 
-{{{
-<wd:field id="sex">
-  <wd:label>Sex</wd:label>
-  <wd:datatype base="enum">
-    <wd:convertor type="enum">
-      <wd:enum>com.example.Sex</wd:enum>
-    </wd:convertor>
-  </wd:datatype>
-  <wd:selection-list type="enum" class="com.example.Sex"/>
-</wd:field>
+{{{
+<wd:field id="sex">
+  <wd:label>Sex</wd:label>
+  <wd:datatype base="enum">
+    <wd:convertor type="enum">
+      <wd:enum>com.example.Sex</wd:enum>
+    </wd:convertor>
+  </wd:datatype>
+  <wd:selection-list type="enum" class="com.example.Sex"/>
+</wd:field>
 }}}
 
 If your enumerated type does not provide a {{{toString()}}} method, the enum convertor will
use the fully qualified class name, followed by the name of the {{{public static final}}}
field referring to each instance, i.e. {{{"com.example.Sex.MALE"}}}, {{{"com.example.Sex.FEMALE"}}}
and so on.
@@ -192,13 +192,13 @@
 This convertor uses the {{{java.text.DecimalFormat}}} class (or {{{com.ibm.icu.text.DecimalFormat}}}
class if it is present in the classpath). This means it can perform locale-dependent, pattern-based
formatting of numbers.
 
 Configuration pseudo-schema:
-{{{
-<wd:convertor type="formatting" variant="integer|number|currency|percent" ? >
-  <wd:patterns>
-    <wd:pattern>....</wd:pattern> ?
-    <wd:pattern locale="lang-COUNTRY">....</wd:pattern> *
-  </wd:patterns> ?
-</wd:convertor>
+{{{
+<wd:convertor type="formatting" variant="integer|number|currency|percent" ? >
+  <wd:patterns>
+    <wd:pattern>....</wd:pattern> ?
+    <wd:pattern locale="lang-COUNTRY">....</wd:pattern> *
+  </wd:patterns> ?
+</wd:convertor>
 }}}
 
 The variant attribute and patterns element are optional. By default, the "number" variant
is used (or for longs: the "integer" variant).
@@ -218,44 +218,44 @@
 This convertor uses the {{{java.text.SimpleDateFormat}}} class (or {{{com.ibm.icu.text.SimpleDateFormat}}}
class if it is present in the classpath). This means it can perform locale-dependent, pattern-based
formatting of dates.
 
 Configuration pseudo-schema:
-{{{
-<wd:convertor type="formatting" variant="date|time|datetime" ? style="short|medium|long|full"
?>
-  <wd:patterns>
-    <wd:pattern>....</wd:pattern> ?
-    <wd:pattern locale="lang-COUNTRY">....</wd:pattern> *
-  </wd:patterns> ?
-</wd:convertor>
+{{{
+<wd:convertor type="formatting" variant="date|time|datetime" ? style="short|medium|long|full"
?>
+  <wd:patterns>
+    <wd:pattern>....</wd:pattern> ?
+    <wd:pattern locale="lang-COUNTRY">....</wd:pattern> *
+  </wd:patterns> ?
+</wd:convertor>
 }}}
 
 Usually you will use either the variant and style attributes or the pattern(s).
 
 For example, the following convertor configuration:
-{{{
-<wd:convertor type="formatting" variant="date" style="short">
+{{{
+<wd:convertor type="formatting" variant="date" style="short">
 }}}
 
 Will give the following for July 15, 2003: 7/15/03. Using style medium it gives "Jul 15,
2003", style long gives "July 15, 2003", and style full gives "Tuesday, July 15, 2003". These
result are locale-dependent of course.
 
 Here's an example of using a formatting pattern:
-{{{
-<wd:convertor type="formatting">
-  <wd:patterns>
-    <wd:pattern>dd/MM/yyyy</wd:pattern>
-  </wd:patterns>
-</wd:convertor>
+{{{
+<wd:convertor type="formatting">
+  <wd:patterns>
+    <wd:pattern>dd/MM/yyyy</wd:pattern>
+  </wd:patterns>
+</wd:convertor>
 }}}
 
 Using the same date, this will now give "15/07/2003".
 
 It is also possible to use different patterns for different locales by using multiple wd:pattern
elements with "locale" attributes, for example:
-{{{
-<wd:convertor type="formatting">
-  <wd:patterns>
-    <wd:pattern>MM/dd/yyyy</wd:pattern>
-    <wd:pattern locale="nl-BE">dd/MM/yyyy</wd:pattern>
-    <wd:pattern locale="fr">dd-MM-yyyy</wd:pattern>
-  </wd:patterns>
-</wd:convertor>
+{{{
+<wd:convertor type="formatting">
+  <wd:patterns>
+    <wd:pattern>MM/dd/yyyy</wd:pattern>
+    <wd:pattern locale="nl-BE">dd/MM/yyyy</wd:pattern>
+    <wd:pattern locale="fr">dd-MM-yyyy</wd:pattern>
+  </wd:patterns>
+</wd:convertor>
 }}}
 
 In this case, if the locale is "nl-BE", the second pattern will be used; if the locale is
"en", the first pattern will be used; and if the locale is "fr-BE" the third pattern will
be used (because when fr-BE is not found, it will first search for "fr" before using the locale-indepent
pattern).

Mime
View raw message