home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / widget_field.xml < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  7.5 KB  |  155 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "document-v10.dtd">
  18.  
  19. <document>
  20.   <header>
  21.     <title>Cocoon Forms: field widget</title>
  22.     <authors>
  23.       <person name="The Apache Cocoon Team" email="dev@cocoon.apache.org"/>
  24.     </authors>
  25.   </header>
  26.   <body>
  27.     <s1 title="Concept">
  28.       <p>The field widget is the most common widget. It is used both for
  29.       text boxes or selection lists. It can be associated with different
  30.       datatypes such as string, long or date to ask for different types of data.</p>
  31.  
  32.       <figure src="images/forms_field_datatype_relation.png" alt="Diagram showing the associations between field, datatype, convertor, selection list and validators."/>
  33.  
  34.       <s2 title="Datatypes">
  35.         <p>A datatype represents a certain type of data, such as a
  36.         string, integer, decimal or date. Each datatype matches to a certain
  37.         Java class. If you associate a field widget with a datatype, its
  38.         setValue(Object) and getValue() methods will take, respectively
  39.         return objects that are instances of that Java class (or subclasses
  40.         thereof).</p>
  41.  
  42.         <p>Each datatype is associated with a <strong>convertor</strong>.
  43.         The task of the convertor is to convert from string representation
  44.         to object representation, and vice versa.</p>
  45.  
  46.         <p>The string to object conversion usually happens when converting
  47.         the value entered by the user to an object. This process can
  48.         fail if the user entered an incorrect string, for example
  49.         <code>abc</code> when a number is required. In this case
  50.         an appropriate validation error will be set on the widget.
  51.         String to object conversion also happens when parsing data
  52.         in selection lists (if the selection list is retrieved as XML)
  53.         and can also be used as part of the <link href="binding.html">binding</link>.</p>
  54.  
  55.         <p>The object to string conversion happens when the state
  56.         of the widget is spit out as XML, this is mostly when injecting
  57.         the widget XML in the publishing pipeline.</p>
  58.  
  59.         <p>By having a field widget associated with a datatype, you can be sure
  60.         that, after successful validation of the widget, retrieving the value
  61.         of the widget will give you an object of the correct type.</p>
  62.  
  63.         <p>The available datatypes and their respective convertors are
  64.         documented in a <link href="datatypes.html">separate document</link>.</p>
  65.       </s2>
  66.  
  67.       <s2 title="Selection lists">
  68.         <p>A field widget can furthermore be associated with a selection list.
  69.         This makes that the field widget could be rendered either as a textbox
  70.         or a list, depending on whether its datatype has a selection list.
  71.         The selection list is related with the datatype: the values in
  72.         the selection list should be of the same type as the datatype.</p>
  73.  
  74.         <p>Selection list data can be specified directly in the form definition
  75.         (for short, unchanging lists), retrieved from external sources (i.e.
  76.         a Cocoon pipeline), or pulled from an oject structure. Full details on
  77.         selection lists are also in a <link href="datatypes.html">separate document</link>.</p>
  78.       </s2>
  79.  
  80.       <s2 title="Conclusion">
  81.         <p>If we wouldn't make these datatype and selection list associations,
  82.         we would need to create specific widgets for each possible combination:
  83.         StringField, LongField, DateField, StringSelectionList, LongSelectionList, ...</p>
  84.       </s2>
  85.     </s1>
  86.  
  87.     <s1 title="Configuration">
  88.       <p>Configuration example:</p>
  89.  
  90.       <source><![CDATA[<fd:field id="..." required="true|false">
  91.   <fd:label>...</fd:label>
  92.   <fd:hint>...</fd:hint>
  93.   <fd:help>...</fd:help>
  94.   <fd:datatype base="...">
  95.      [...]
  96.   </fd:datatype>
  97.   <fd:selection-list .../>
  98.   <fd:validation>
  99.      [...]
  100.   </fd:validation>
  101.   <fd:on-value-changed>
  102.      [...]
  103.   </fd:on-value-changed>
  104. </fd:field>]]></source>
  105.  
  106.       <p>The field element takes a required <strong>id</strong> attribute.
  107.       This id should be unique among all widgets in the same container (i.e. inside
  108.       the same fd:widgets element).</p>
  109.  
  110.       <p>The <strong>required</strong> attribute is optional, by default it is false.
  111.       It indicates whether this field is required. This is a static property of the
  112.       widget. If you want the field to be "conditionally required", then set this
  113.       to false and use custom validation logic to check the requiredness of the field.</p>
  114.  
  115.       <p>The <strong>fd:label</strong> element contains the label for this widget.
  116.       This element is optional. It can contain mixed content. For internationalised
  117.       labels, use i18n-tags in combination with Cocoon's I18nTransformer.</p>
  118.  
  119.       <p>The <strong>fd:hint</strong> element contains a hint for the form control of this widget.
  120.       This element is optional. It can contain a hint about the input control.
  121.       For internationalised labels, use i18n-tags in combination with Cocoon's I18nTransformer.</p>
  122.  
  123.       <p>The <strong>fd:help</strong> element contains more help for the form control of this widget.
  124.       This element is optional. It can contain text help about the input control.
  125.       For internationalised labels, use i18n-tags in combination with Cocoon's I18nTransformer.</p>
  126.  
  127.       <p>The <strong>fd:datatype</strong> element indicates the datatype for
  128.       this field. This element is required. The base attribute specifies
  129.       on which built-in type this datatype should be based. The contents
  130.       of the fd:datatype element can contain further configuration
  131.       information for the datatype. The possible datatypes and their
  132.       configuration options are described <link href="datatypes.html">over here</link>.</p>
  133.  
  134.       <p>The <strong>fd:selection-list</strong> element is used to associate
  135.       a selection list with this field. See <link href="datatypes.html">Datatypes</link>
  136.       for more details.</p>
  137.  
  138.       <p>The <strong>fd:validation</strong> element specifies widget validators.
  139.       See <link href="validation.html">Validation</link> for more details.</p>
  140.  
  141.       <p>The <strong>fd:on-value-changed</strong> element specifies event
  142.       handlers to be executed in case the value of this field changes.
  143.       See also <link href="eventhandling.html">Event Handling</link>. The interface to be implemented
  144.       for Java event listeners is <code>org.apache.cocoon.forms.event.ValueChangedListener</code>.
  145.       The WidgetEvent subclass is <code>org.apache.cocoon.forms.event.ValueChangedEvent</code>.</p>
  146.  
  147.       <p><strong>Note:</strong> Events used in <fd:on-value-changed>
  148.       require that the form instance is stored serverside (because otherwise
  149.       CForms doesn't know what the previous values of the fields were).
  150.       This is automatically the case when you use flowscript. If you don't use
  151.       flowscript you could store the form instance in e.g. the session.</p>
  152.     </s1>
  153.   </body>
  154. </document>
  155.