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 / binding.xml < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  26.5 KB  |  662 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: Binding Framework</title>
  22.     <authors>
  23.       <person name="The Apache Cocoon Team" email="dev@cocoon.apache.org"/>
  24.     </authors>
  25.   </header>
  26.   <body>
  27.     <s1 title="Intro">
  28.       <p>Likely you will want to use CForms to "edit stuff", such as the properties
  29.       of a bean or data from an XML document (we'll simply use the term object to
  30.       refer to either of these). This supposes that before you show the form,
  31.       you copy the data from the object to the form, and after the form has been
  32.       validated, you copy the data in the form back to the object. To avoid having
  33.       to write actual code for this, a binding framework is available.</p>
  34.  
  35.       <p>The same illustration as in the introduction,
  36.       but now extended with the binding, can be viewed <link href="images/forms_schema_withbinding.png">here</link>.</p>
  37.  
  38.       <p>The basic definition of a binding is as follows (if you don't know Java, just ignore this):</p>
  39.  
  40.       <source><![CDATA[public interface Binding {
  41.     public void loadFormFromModel(Widget frmModel, Object objModel);
  42.     public void saveFormToModel(Widget frmModel, Object objModel);
  43. }]]></source>
  44.  
  45.       <p>A binding can work with any object and can perform the binding in any
  46.       possible way. Currently one implementation is available, based on
  47.       <link href="http://jakarta.apache.org/commons/jxpath/index.html">JXPath</link>.
  48.       JXPath allows to address data in both beans and XML documents using
  49.       <link href="http://www.w3.org/TR/xpath">XPath</link> expressions, so this
  50.       binding implementation can be used both with beans and XML documents.
  51.       The rest of this document will focus on this implementation.</p>
  52.  
  53.       <p>The binding is configured using an XML file. This XML file contains
  54.       elements in the fb namesspace (Forms Binding):</p>
  55.  
  56.       <source><![CDATA[http://apache.org/cocoon/forms/1.0#binding]]></source>
  57.     </s1>
  58.  
  59.     <s1 title="What does a binding file look like?">
  60.       <p>To give you an idea of what a binding file looks like, below a
  61.       very simple example is shown.</p>
  62.  
  63.       <source><![CDATA[<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" path="/" >
  64.     <fb:value id="firstname" path="firstName"/>
  65.     <fb:value id="lastname" path="lastName"/>
  66.     <fb:value id="email" path="email"/>
  67. </fb:context>]]></source>
  68.  
  69.       <p>The id attribute identifies the widget. The path attribute is the address
  70.       of the items in the target object (a Javabean or an XML document).
  71.       The paths can be arbitrary JXPath expressions.</p>
  72.  
  73.       <p>[Convention] Let's call all elements in the fb namespace "binding elements".
  74.       They all cause a binding-related action to be performed.</p>
  75.  
  76.       <p>The <code>fb:context</code> element changes the <link href="http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/JXPathContext.html">JXPath context</link>
  77.       to the specified path. The path expressions on the binding elements occuring
  78.       inside the context element will then be evaluated in this context, thus relative
  79.       to the path specified on the fb:context element.</p>
  80.  
  81.       <p>The <code>fb:value</code> element is used to bind the value of a widget.</p>
  82.  
  83.       <p>The binding framework can do much more than what is shown in the simple
  84.       example above, so read on for more meat.</p>
  85.     </s1>
  86.  
  87.     <s1 title="Quick reference of supported binding elements">
  88.       <table>
  89.         <tr>
  90.           <th>Element</th>
  91.           <th>Description</th>
  92.           <th>Attributes</th>
  93.           <th>child elements</th>
  94.         </tr>
  95.         <tr>
  96.           <td>fb:*</td>
  97.           <td>common settings for all bindings</td>
  98.           <td>direction</td>
  99.           <td>not applicable, see specific elements</td>
  100.         </tr>
  101.         <tr>
  102.           <td>fb:context</td>
  103.           <td>changes the JXPath context</td>
  104.           <td>path</td>
  105.           <td>any</td>
  106.         </tr>
  107.         <tr>
  108.           <td>fb:value</td>
  109.           <td>binds the value of widgets</td>
  110.           <td>id, path</td>
  111.           <td>fb:on-update, fd:convertor</td>
  112.         </tr>
  113.         <tr>
  114.           <td>fb:aggregate</td>
  115.           <td>binds aggregatefield widgets</td>
  116.           <td>id, path</td>
  117.           <td>fb:value</td>
  118.         </tr>
  119.         <tr>
  120.           <td>fb:repeater</td>
  121.           <td>binds repeater widgets</td>
  122.           <td>id, parent-path, row-path, unique-row-id
  123.           (deprecated), unique-path (deprecated)</td>
  124.           <td>fd:convertor (deprecated), fb:on-bind,
  125.           fb:on-delete-row, fb:on-insert-row, fb:unique-row</td>
  126.         </tr>
  127.         <tr>
  128.           <td>fb:unique-row</td>
  129.           <td>specifies unique fields for a repeater row</td>
  130.           <td>none</td>
  131.           <td>fb:unique-field</td>
  132.         </tr>
  133.         <tr>
  134.           <td>fb:unique-field</td>
  135.           <td>specifies unique field for a repeater row</td>
  136.           <td>id, path</td>
  137.           <td>fd:convertor</td>
  138.         </tr>
  139.         <tr>
  140.           <td>fb:set-attribute</td>
  141.           <td>sets an attribute to a fixed value</td>
  142.           <td>name, value</td>
  143.           <td>none</td>
  144.         </tr>
  145.         <tr>
  146.           <td>fb:delete-node</td>
  147.           <td>deletes the current context node</td>
  148.           <td>none</td>
  149.           <td>none</td>
  150.         </tr>
  151.         <tr>
  152.           <td>fb:insert-node</td>
  153.           <td>insert a node in an XML document</td>
  154.           <td>src, xpath</td>
  155.           <td>piece of XML that should be inserted</td>
  156.         </tr>
  157.         <tr>
  158.           <td>fb:insert-bean</td>
  159.           <td>inserts an object in a list-type bean property</td>
  160.           <td>classname, addmethod</td>
  161.           <td>none</td>
  162.         </tr>
  163.         <tr>
  164.           <td>fb:simple-repeater</td>
  165.           <td>binds repeater widgets</td>
  166.           <td>id, parent-path,row-path, clear-before-load, delete-parent-if-empty</td>
  167.           <td>any</td>
  168.         </tr>
  169.         <tr>
  170.           <td>fb:javascript</td>
  171.           <td>write binding logic in Javascript</td>
  172.           <td>id, path</td>
  173.           <td>fb:load-form, fb:save-form</td>
  174.         </tr>
  175.         <tr>
  176.           <td>fb:custom</td>
  177.           <td>write binding logic in Java</td>
  178.           <td>id, path, class, builderclass,factorymethod</td>
  179.           <td>fb:config</td>
  180.         </tr>
  181.       </table>
  182.     </s1>
  183.  
  184.     <s1 title="Detailed reference of binding elements">
  185.       <s2 title="fb:*/@direction">
  186.         <p>All Bindings share the ability to have the two distinct actions
  187.         they provide (i.e. load and save) been enabled or disabled by setting
  188.         the attribute direction to one of the following values:</p>
  189.  
  190.         <table>
  191.           <tr>
  192.             <th>value</th>
  193.             <th>load active?</th>
  194.             <th>save active?</th>
  195.           </tr>
  196.           <tr>
  197.             <td>both(default)</td>
  198.             <td>yes</td>
  199.             <td>yes</td>
  200.           </tr>
  201.           <tr>
  202.             <td>load</td>
  203.             <td>yes</td>
  204.             <td>no</td>
  205.           </tr>
  206.           <tr>
  207.             <td>save</td>
  208.             <td>no</td>
  209.             <td>yes</td>
  210.           </tr>
  211.         </table>
  212.  
  213.         <p>The default value 'both' for this attribute makes its use optional.</p>
  214.  
  215.         <p><strong>NOTE</strong>: this setting replaces the @readonly attribute that
  216.         was available only on selected bindings.</p>
  217.       </s2>
  218.  
  219.       <s2 title="fb:context">
  220.         <p>Attributes:</p>
  221.         <ul>
  222.           <li>path</li>
  223.           <li>direction (optional)</li>
  224.         </ul>
  225.         <p>Child elements: any</p>
  226.  
  227.         <p>The <code>fb:context</code> element changes the JXPath context to the
  228.         specified path. The path expressions on the binding elements occuring inside
  229.         the context element will then be evaluated in this context, thus relative to
  230.         the path specified on the <code>fb:context</code> element.</p>
  231.  
  232.         <p>The <code>fb:context</code> element is usually used in two occasions.
  233.         First of all, it is used as the root element of the binding file; because an
  234.         XML file must always have one root element, and you will usually want to
  235.         perform more than one binding action.</p>
  236.  
  237.         <p>Secondly, you use <code>fb:context</code> if you need to address multiple
  238.         items having a common base path. On the one hand, this saves you on typing
  239.         and helps readability, and on the other hand, this improves the performance
  240.         of the binding. To illustrate this with an example, instead of doing this:</p>
  241.  
  242.         <source><![CDATA[...
  243. <fb:value id="firstname" path="info/person/firstName"/>
  244. <fb:value id="lastname" path="info/person/lastName"/>
  245. ...]]></source>
  246.  
  247.         <p>it is better to do this:</p>
  248.  
  249.         <source><![CDATA[...
  250. <fb:context path="info/person">
  251.   <fb:value id="firstname" path="firstName"/>
  252.   <fb:value id="lastname" path="lastName"/>
  253. </fb:context>
  254. ...]]></source>
  255.  
  256.       </s2>
  257.  
  258.       <s2 title="fb:value">
  259.         <p>Attributes:</p>
  260.         <ul>
  261.           <li>id</li>
  262.           <li>path</li>
  263.           <li>direction (optional)</li>
  264.         </ul>
  265.         <p>Child elements:</p>
  266.         <ul>
  267.           <li>fb:on-update (optional)</li>
  268.           <li>fd:convertor (note the fd: namespace!) (optional)</li>
  269.         </ul>
  270.  
  271.         <p>This binding element is used to bind the value of a widget.</p>
  272.  
  273.         <p>The <code>fb:on-update</code> element (which itself has no attributes),
  274.         can contain one or more binding elements that will be executed if the value
  275.         of the widget has changed, and thus if the object has been updated. For example,
  276.         you could use the <code>fb:set-attribute</code> binding to set the
  277.         value of an attribute <code>changed</code> to <code>true</code>.</p>
  278.  
  279.         <p>The <code>fd:convertor</code> element has the same purpose as the
  280.         <code>fd:convertor</code> element in the form definition: it converts
  281.         between objects (numbers, dates) and strings. This is mostly used when
  282.         binding to XML documents. Suppose you have defined a certain widget in
  283.         a form definition to have a "date" datatype, and you want to bind to
  284.         an XML document which contains the date in the XML Schema date representation,
  285.         then you could define a convertor as follows:</p>
  286.  
  287.         <source><![CDATA[<fb:value id="birthday" path="person/birthday">
  288.   <fd:convertor datatype="date" type="formatting">
  289.     <fd:patterns>
  290.       <fd:pattern>yyyy-MM-dd</fd:pattern>
  291.     </fd:patterns>
  292.   </fd:convertor>
  293. </fb:value>]]></source>
  294.  
  295.         <p>The datatype attribute on the <code>fd:convertor</code> element, which you
  296.         don't have to specify in the form definition, identifies the datatype to which
  297.         the convertor belongs.</p>
  298.       </s2>
  299.  
  300.       <s2 title="fb:aggregate">
  301.         <p>Attributes:</p>
  302.         <ul>
  303.           <li>id</li>
  304.           <li>path</li>
  305.           <li>direction</li>
  306.         </ul>
  307.         <p>Child elements:</p>
  308.         <ul>
  309.           <li>fb:value elements</li>
  310.         </ul>
  311.  
  312.         <p>The <code>fb:aggregate</code> element is used to bind aggregatefields. Remember
  313.         that aggregatefields are a special type of widget that groups multiple field widgets
  314.         and lets the user edit their values in one textbox, splitting the values out to the
  315.         different widgets on submit based on a regexp.</p>
  316.  
  317.         <p>The <code>fb:aggregate</code> binding allows to bind the values of the individual
  318.         field widgets out of which an aggregatefield widget consists. The bindings for these
  319.         field widgets are specified by the fb:value child elements.</p>
  320.       </s2>
  321.  
  322.       <s2 title="fb:repeater">
  323.         <p>Attributes:</p>
  324.         <ul>
  325.           <li>id</li>
  326.           <li>parent-path</li>
  327.           <li>row-path</li>
  328.           <li>unique-row-id (deprecated)</li>
  329.           <li>unique-path (deprecated)</li>
  330.           <li>row-path-insert (optional)</li>
  331.           <li>direction (optional)</li>
  332.         </ul>
  333.         <p>Child elements:</p>
  334.         <ul>
  335.           <li>fb:identity</li>
  336.           <li>fd:convertor (deprecated)</li>
  337.           <li>fb:on-bind</li>
  338.           <li>fb:on-delete-row</li>
  339.           <li>fb:on-insert-row</li>
  340.         </ul>
  341.         <p><strong>NOTE:</strong> The attributes <code>unique-row-id</code> and
  342.         <code>unique-path</code> and the child element <code>fd:convertor</code>
  343.         are deprecated in favor of <fb:unique-row>.</p>
  344.  
  345.         <p>The <code>fb:repeater</code> binding binds repeaters based on the concept
  346.         that each row in the repeater is identified by one or more widgets uniquely.
  347.         This unique identification is necessary to know which rows in the repeater
  348.         correspond to which objects in the target collection. Newly added rows in
  349.         the repeater can (but should not) have a null value for this identification
  350.         widget(s). Typically this/these widget(s) will not editable, so in most cases
  351.         it will be an output widget. If you don't need the identification widget(s)
  352.         at the client you don't need to add them to the template at all! You only have
  353.         to specify <code>direction="load"</code> to this/these widget(s) then.
  354.         This prevents the database IDs from getting to the client.</p>
  355.  
  356.         <p>The <code>id</code> attribute should contain the id of the repeater.</p>
  357.  
  358.         <p>The <code>unique-row-id</code> attribute specifies the id of the widget
  359.         appearing on each repeater row that contains the unique identification for
  360.         that row. The unique-path attribute contains the corresponding path in the object model.</p>
  361.  
  362.         <p><strong>NOTE</strong>: Both attributes are deprecated. Please use <code><fb:identity></code> instead.</p>
  363.  
  364.         <p>The <code>parent-path</code> and <code>row-path</code> attributes can best be
  365.         understood when described differently for XML documents and Javabeans.</p>
  366.  
  367.         <p>For XML documents: If you have an XML structure like this:</p>
  368.  
  369.         <source><![CDATA[<things>
  370.    <thing ... />
  371.    <thing ... />
  372. </things>]]></source>
  373.  
  374.         <p>then the parent-path attribute contains the path to the containing
  375.         element ("things") and the row-path attribute contains the path to the
  376.         repeating element ("thing").</p>
  377.  
  378.         <p>For beans: if your bean has a property "things" which is a Collection
  379.         [or whathever JXPath supports as lists], then the parent-path should simply
  380.         contain "." and the row-path "things".</p>
  381.  
  382.         <p>For both beans and XML documents there is an optional attribute
  383.         row-path-insert which functions just like the row-path but is used
  384.         for the nested on-insert-row binding (see below). By default the row-path-insert
  385.         just takes the value of the row-path. By explicitely setting them different
  386.         one can exploit one of the following use cases:</p>
  387.  
  388.         <ul>
  389.           <li>(1) use xpath-predicates in the row-path (note that you can not do that on the row-path-insert)</li>
  390.           <li>(2) save the inserted rows in a different target-node of the backend model.</li>
  391.         </ul>
  392.  
  393.         <p>A child element <code>fd:convertor</code> can be used to specify the convertor
  394.         to use in case the unique-id from the model is a String (typical for XML documents)
  395.         and the matching widget inside the repeater has a different type.</p>
  396.  
  397.         <p><strong>NOTE:</strong> This element is deprecated at that place as it
  398.         is only used in combination with the deprecated attributes unique-row-id
  399.         and unique-path. Please use <code><fb:identity></code> instead.</p>
  400.  
  401.         <p>The three remaining child elements <code>fb:on-bind</code>, <code>fb:on-delete-row</code>,
  402.         <code>fb:on-insert-row</code> should contain the binding elements that have to
  403.         be executed in case of these three events.</p>
  404.  
  405.         <p>The children of the <code>fb:on-bind</code> element are executed when
  406.         an existing repeater row is updated, or after inserting a new row. The JXPath
  407.         context is automatically changed to match the current row.</p>
  408.  
  409.         <p>The children of the <code>fb:on-delete-row</code> element are executed
  410.         when a repeater row has been deleted. If you want to delete the row, then put
  411.         a <code><fb:delete-node/></code> in there. Alternatively, you could also
  412.         use the <code>fb:set-attribute</code> binding to set e.g. an attribute status to deleted.</p>
  413.  
  414.         <p>The children of the <code>fb:on-insert-row</code> are executed in case a
  415.         new row has been added to the repeater. Typically this will contain a
  416.         <code>fb:insert-node</code> or a <code>fb:insert-bean</code> binding (see
  417.         the descriptions of these binding elements for more details).</p>
  418.  
  419.         <p>The childrens of the <code>fb:unique-row</code> specify the widgets appearing
  420.         on each repeater row for the unique identification of that row. Each <fb:unique-field>
  421.         child specifies one widget.</p>
  422.       </s2>
  423.  
  424.       <s2 title="fb:identity">
  425.         <p>Child elements:</p>
  426.         <ul>
  427.           <li>fb:value widget-bindings that make up the identity</li>
  428.         </ul>
  429.  
  430.         <p>The <code><fb:identity></code> is just a container for the child elements
  431.         specifying the bindings of the identification widgets.</p>
  432.  
  433.         <p>The nested elements just describe regular value bindings that can
  434.         declare their own convertor if needed.</p>
  435.  
  436.         <p><strong>NOTE:</strong> This 'identity' binding is only active in the
  437.         'load' operation, so specifying the direction="save" is meaningless.</p>
  438.       </s2>
  439.  
  440.       <s2 title="fb:set-attribute">
  441.         <p>Attributes:</p>
  442.         <ul>
  443.           <li>name</li>
  444.           <li>value</li>
  445.           <li>direction (optional)</li>
  446.         </ul>
  447.         <p>Child elements: none</p>
  448.  
  449.         <p>Set the value of the attribute specified in the <code>name</code> attribute to the
  450.         fixed string value specified in the <code>value</code> attribute.</p>
  451.  
  452.         <p><strong>NOTE:</strong> This binding is never active in the 'load' operation,
  453.         so there is no need to specify the <code>direction="save"</code> to protect you model
  454.         from being changed during load.</p>
  455.       </s2>
  456.  
  457.       <s2 title="fb:delete-node">
  458.         <p>Attributes:</p>
  459.         <ul>
  460.           <li>direction (optional)</li>
  461.         </ul>
  462.  
  463.         <p>Child elements: none</p>
  464.  
  465.         <p>Deletes the current context node.</p>
  466.  
  467.         <p><strong>NOTE:</strong> This binding is never active in the 'load' operation,
  468.         so there is no need to specify the <code>direction="save"</code> to protect you model from
  469.         being changed during load.</p>
  470.       </s2>
  471.  
  472.       <s2 title="fb:insert-node">
  473.         <p>Attributes:</p>
  474.         <ul>
  475.           <li>src (optional)</li>
  476.           <li>xpath (optional, only in combination with src)</li>
  477.           <li>direction (optional)</li>
  478.         </ul>
  479.  
  480.         <p>Child elements: the piece of XML that should be inserted</p>
  481.  
  482.         <p>This binding element can only be used when the target object is an XML document (DOM-tree).</p>
  483.  
  484.         <p>It inserts the content of the <code>fb:insert-node</code> element as child
  485.         of the current context element, or, if a src attribute is specified, retrieves
  486.         the XML from the specified source and inserts that as child of the current
  487.         context element. In this last case, you can also supply an xpath attribute
  488.         to select a specific element from the retrieved source.</p>
  489.  
  490.         <p><strong>NOTE:</strong> This binding is never active in the 'load' operation,
  491.         so there is no need to specify the <code>direction="save"</code> to protect you model
  492.         from being changed during load.</p>
  493.       </s2>
  494.  
  495.       <s2 title="fb:insert-bean">
  496.         <p>Attributes:</p>
  497.         <ul>
  498.           <li>classname</li>
  499.           <li>addmethod</li>
  500.           <li>direction (optional)</li>
  501.         </ul>
  502.  
  503.         <p>This binding element can only be used when the target object is a Javabean.</p>
  504.  
  505.         <p>It instantiates a new object of the type specified in the classname
  506.         attribute and calls the method specified in the addmethod attribute on the
  507.         current context object with the newly instantiated object as argument.</p>
  508.  
  509.         <p><strong>NOTE:</strong> This binding is never active in the 'load' operation,
  510.         so there is no need to specify the <code>direction="save"</code> to protect you model
  511.         from being changed during load.</p>
  512.       </s2>
  513.  
  514.       <s2 title="fb:simple-repeater">
  515.         <p>Attributes:</p>
  516.         <ul>
  517.           <li>id</li>
  518.           <li>parent-path (same as in fb:repeater)</li>
  519.           <li>row-path (same as in fb:repeater)</li>
  520.           <li>clear-before-load (default true)</li>
  521.           <li>delete-parent-if-empty (default false)</li>
  522.           <li>direction (optional)</li>
  523.         </ul>
  524.  
  525.         <p>Child elements: any</p>
  526.  
  527.         <p>A simple repeater binding that will replace (i.e. delete then re-add all) its content.</p>
  528.  
  529.         <p>Works with XML or with JavaBeans if a JXPath factory is set on the binding context.</p>
  530.       </s2>
  531.  
  532.       <s2 title="fb:javascript">
  533.         <p>Attributes:</p>
  534.         <ul>
  535.           <li>id</li>
  536.           <li>path</li>
  537.           <li>direction (optional)</li>
  538.         </ul>
  539.  
  540.         <p>Child elements:</p>
  541.         <ul>
  542.           <li>fb:load-form</li>
  543.           <li>fb:save-form</li>
  544.         </ul>
  545.  
  546.         <p>Specifies the binding using two JavaScript snippets, respectively for loading and saving the form.</p>
  547.  
  548.         <p>Example:</p>
  549.  
  550.         <source><![CDATA[<fb:javascript id="foo" path="@foo">
  551.   <fb:load-form>
  552.     var appValue = jxpathPointer.getValue();
  553.     var formValue = doLoadConversion(appValue);
  554.     widget.setValue(formValue);
  555.   </fb:load-form>
  556.   <fb:save-form>
  557.     var formValue = widget.getValue();
  558.     var appValue = doSaveConversion(formValue);
  559.     jxpathPointer.setValue(appValue);
  560.   </fb:save-form>
  561. </fb:javascript>]]></source>
  562.  
  563.         <p>This example is rather trivial and could be replaced by a simple
  564.         <code><fb:value></code>, but it shows the available variables in the script:</p>
  565.  
  566.         <ul>
  567.           <li><code>widget:</code> the widget identified by the <code>id</code> attribute,</li>
  568.           <li><code>jxpathPointer:</code> the JXPath pointer corresponding to the <code>path</code> attribute,</li>
  569.           <li><code>jxpathContext</code> (not shown): the JXPath context corresponding to the <code>path</code> attribute</li>
  570.         </ul>
  571.  
  572.         <p>It's much more interesting to fill a selection list via <code>fb:javascript</code>
  573.         as there is no built-in element for it at the moment. Imagine your binding bean
  574.         contains a collection field:</p>
  575.  
  576.         <source><![CDATA[<fb:javascript id="selectionListWidget" path="objectCollection" direction="load">
  577.   <fb:load-form>
  578.     var collection = jxpathPointer.getNode();
  579.     widget.setSelectionList(collection, "id", "name")
  580.   </fb:load-form>
  581. </fb:javascript>]]></source>
  582.  
  583.         <p><strong>NOTE:</strong></p>
  584.  
  585.         <ul>
  586.           <li>The <code><fb:save-form></code> snippet should be ommitted
  587.           if the <code>direction</code> attribute is set to load.</li>
  588.           <li>The <code><fb:load-form></code> snippet should be ommitted if the
  589.           <code>direction</code> attribute is set to save.</li>
  590.           <li>The <code>@readonly</code> attribute supported in early versions of this
  591.           binding has been replaced by the @direction attribute as supported now on all binding elements.</li>
  592.         </ul>
  593.       </s2>
  594.  
  595.       <s2 title="fb:custom">
  596.         <p>Attributes:</p>
  597.         <ul>
  598.           <li>id (optional, if not provided the containing widget-context will be passed)</li>
  599.           <li>path (optional, if not provided "." is assumed)</li>
  600.           <li>direction (optional)</li>
  601.           <li>class (optional, if not present @builderclass and @factorymethod should be)</li>
  602.           <li>builderclass (optional)</li>
  603.           <li>factorymethod (optional)</li>
  604.         </ul>
  605.  
  606.         <p>Child elements:</p>
  607.         <ul>
  608.           <li>fb:config</li>
  609.         </ul>
  610.  
  611.         <p>Allows to specify your own user-defined binding to be written in Java.
  612.         There are two essential modes of operation reflected in two examples:</p>
  613.  
  614.         <p>Example 1 - No configuration required:</p>
  615.  
  616.         <source><![CDATA[<fb:custom id="custom" path="custom-value"
  617.       class="org.apache.cocoon.forms.samples.bindings.CustomValueWrapBinding"/>]]></source>
  618.  
  619.         <p>This describes the classname of your user defined binding class.</p>
  620.  
  621.         <p>Above imposes the following requirements:</p>
  622.  
  623.         <ol>
  624.           <li>there is a <code>class</code> CustomValueWrapBinding available in the specified package</li>
  625.           <li>it has a default (i.e. no arguments) constructor</li>
  626.           <li>it is a subclass of org.apache.cocoon.forms.binding.AbstractCustomBinding</li>
  627.         </ol>
  628.  
  629.         <p>This last will impose the implementation of two methods:</p>
  630.  
  631.         <ul>
  632.           <li>void doLoad(Widget widget, JXPathContext context) throws BindingException;</li>
  633.           <li>void doSave(Widget widget, JXPathContext context) throws BindingException;</li>
  634.         </ul>
  635.  
  636.         <p>where the available arguments are</p>
  637.  
  638.         <ul>
  639.           <li><code>widget</code>: the widget identified by the <code>id</code> attribute,</li>
  640.           <li><code>context</code>: the JXPath context corresponding to the <code>path</code> attribute</li>
  641.         </ul>
  642.  
  643.         <p>Example 2 - with nested configuration:</p>
  644.  
  645.         <source><![CDATA[  <fb:custom id="config" path="config-value"
  646.       builderclass="org.apache.cocoon.forms.samples.bindings.CustomValueWrapBinding"
  647.       factorymethod="createBinding" >
  648.       <fb:config prefixchar="[" suffixchar="]" />
  649.   </fb:custom>]]></source>
  650.  
  651.         <p>The additional requirements to your user defined classes are now:</p>
  652.  
  653.         <ol>
  654.           <li>there is a <code>builderclass</code> CustomValueWrapBinding class having a static <code>factorymethod</code></li>
  655.           <li>that can (optionally) take an org.w3c.dom.Element holding it's configuration</li>
  656.           <li>and return an instance of your own user-defined binding which must be a non abstract subclass of org.apache.cocoon.forms.binding.AbstractCustomBinding</li>
  657.         </ol>
  658.       </s2>
  659.     </s1>
  660.   </body>
  661. </document>
  662.