Return-Path: Delivered-To: apmail-cocoon-docs-archive@www.apache.org Received: (qmail 9630 invoked from network); 19 Jul 2004 18:23:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 19 Jul 2004 18:23:13 -0000 Received: (qmail 68995 invoked by uid 500); 19 Jul 2004 18:22:40 -0000 Delivered-To: apmail-cocoon-docs-archive@cocoon.apache.org Received: (qmail 68936 invoked by uid 500); 19 Jul 2004 18:22:39 -0000 Mailing-List: contact docs-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: docs@cocoon.apache.org Delivered-To: mailing list docs@cocoon.apache.org Received: (qmail 68854 invoked by uid 99); 19 Jul 2004 18:22:38 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Mon, 19 Jul 2004 11:22:37 -0700 Received: (qmail 9315 invoked from network); 19 Jul 2004 18:22:36 -0000 Received: from localhost.hyperreal.org (HELO minotaur.apache.org) (127.0.0.1) by localhost.hyperreal.org with SMTP; 19 Jul 2004 18:22:36 -0000 Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: docs@cocoon.apache.org To: docs@cocoon.apache.org Subject: =?iso-8859-1?q?=5BCocoon_Wiki=5D_Updated=3A__WoodyDatatypeReference?= Date: Mon, 19 Jul 2004 18:22:35 -0000 Message-ID: <20040719182235.9288.27691@minotaur.apache.org> X-Spam-Rating: localhost.hyperreal.org 1.6.2 0/1000/N X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Date: 2004-07-19T11:22:35 Editor: StephanNiedermeier 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: = -{{{ - +{{{ + }}} = The '''base''' attribute refers to one of the built-in datatypes such as s= tring or long. @@ -16,14 +16,14 @@ =3D=3D Convertors =3D=3D = A datatype also needs a convertor. The purpose of a convertor is to conver= t between string and object representations of values. There is always a de= fault convertor, but you change or configure that using the '''wd:convertor= ''' element. Here's an example for dates: -{{{ - - - - dd/MM/yyyy - - - +{{{ + + + + dd/MM/yyyy + + + }}} = The '''type''' attribute on the wd:convertor element is optional, if not s= pecified the default one will be used (configured in the cocoon.xconf). Any= further content of the wd:convertor element is specific to the convertor i= mplementation and will be documented in a seperate section. @@ -32,17 +32,17 @@ = Widgets that have a datatype can also have a selection list. Since selecti= on lists are associated with datatypes, we discuss them here. The selection= list can be defined inline or read from an external source. Example of inl= ine declaration: = -{{{ - - - - - - three - - - - +{{{ + + + + + + three + + + + }}} = Each item in the selection-list can have a value (specified in the value a= ttribute) 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 c= ontain mixed content. @@ -50,35 +50,35 @@ To set a default selection, just set the value of the widget containing th= e selection list. = Example of getting a selection list from an external source: -{{{ - - +{{{ + + }}} = 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 elemen= t. = 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 def= ined it inline. This has the consequence that if the XML produced by the so= urce 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 a= n attribute called "dynamic" with value "true", for example: -{{{ - - +{{{ + + }}} = If the datatype is different from string, Woody will need to convert the s= tring values that appear in the selection list to their object equivalent. = This conversion is normally done using the same convertor as the datatype i= n which the selection list appears, but you can also specify a different on= e. Here's an example for a date selection list: -{{{ - - - - - yyyyMMdd - - - - - - - - - +{{{ + + + + + yyyyMMdd + + + + + + + + + }}} = If there is a wd:convertor element, it should always be the first child el= ement of the wd:selection-list element. This works of course also for selec= tion lists retrieved from external sources. @@ -92,20 +92,20 @@ Example: = In flowscript: -{{{ -var data =3D new Object(); - -data.cityList =3D new Array(2); -data.cityList[0] =3D {value:"AL", label:"Alabama"}; -data.cityList[1] =3D {value:"AK", label:"Alaska"}; - -form.showForm("flow/myform.form", data); +{{{ +var data =3D new Object(); + +data.cityList =3D new Array(2); +data.cityList[0] =3D {value:"AL", label:"Alabama"}; +data.cityList[1] =3D {value:"AK", label:"Alaska"}; + +form.showForm("flow/myform.form", data); }}} = and the corresponding selection list definition: = -{{{ - +{{{ + }}} = =3D=3D Selection lists: enum implementation =3D=3D @@ -114,69 +114,69 @@ = Example: = -{{{ - +{{{ + }}} = outputs: = -{{{ - - - - - com.example.Sex.MALE - - - - - com.example.Sex.FEMALE - - - +{{{ + + + + + com.example.Sex.MALE + + + + + com.example.Sex.FEMALE + + + }}} = If you don't want an initial null value, add a '''nullable=3D"false"''' at= tribute to the '''wd:selection-list''' element. This applies only to '''enu= m''' type selection lists. = =3D Available datatypes =3D = -||'''Woody Datatype'''||'''Java class'''||||Convertors -||string||{{{java.lang.String}}}||Strings obviously don't support any conv= ertors, 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 conv= ertors, 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|| = =3D=3D Enumerated datatypes =3D=3D = 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 =3D new Sex("M"); - public static final Sex FEMALE =3D new Sex("F"); - private String code; - - private Sex(String code) { this.code =3D code; } -} +{{{ +package com.example; + +public class Sex { + + public static final Sex MALE =3D new Sex("M"); + public static final Sex FEMALE =3D new Sex("F"); + private String code; + + private Sex(String code) { this.code =3D code; } +} }}} = The following snippet shows the usage of this type: = -{{{ - - Sex - - - com.example.Sex - - - - +{{{ + + Sex + + + com.example.Sex + + + + }}} = If your enumerated type does not provide a {{{toString()}}} method, the en= um 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 m= eans it can perform locale-dependent, pattern-based formatting of numbers. = Configuration pseudo-schema: -{{{ - - - .... ? - .... * - ? - +{{{ + + + .... ? + .... * + ? + }}} = 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 dat= es. = Configuration pseudo-schema: -{{{ - - - .... ? - .... * - ? - +{{{ + + + .... ? + .... * + ? + }}} = Usually you will use either the variant and style attributes or the patter= n(s). = For example, the following convertor configuration: -{{{ - +{{{ + }}} = 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 give= s "Tuesday, July 15, 2003". These result are locale-dependent of course. = Here's an example of using a formatting pattern: -{{{ - - - dd/MM/yyyy - - +{{{ + + + dd/MM/yyyy + + }}} = Using the same date, this will now give "15/07/2003". = It is also possible to use different patterns for different locales by usi= ng multiple wd:pattern elements with "locale" attributes, for example: -{{{ - - - MM/dd/yyyy - dd/MM/yyyy - dd-MM-yyyy - - +{{{ + + + MM/dd/yyyy + dd/MM/yyyy + dd-MM-yyyy + + }}} = In this case, if the locale is "nl-BE", the second pattern will be used; i= f 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).