You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2003/07/22 13:50:46 UTC

cvs commit: cocoon-2.1/src/blocks/woody/samples/forms form2_bind.xml form2_data.xml form2_model.xml form2_template.xsp

bruno       2003/07/22 04:50:46

  Added:       src/blocks/woody/samples/forms form2_bind.xml form2_data.xml
                        form2_model.xml form2_template.xsp
  Log:
  Binding framework patch by Marc Portier (see bugzilla 21671)
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form2_bind.xml
  
  Index: form2_bind.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
      | Binding template between 
      |   - form_data file (backend)
      |   - and form_model file
      | Mappings
      |   woody-widget              <> backend-xpath
      |   __________________________________________________
      |   {context}                    /data/wrapper/context
      |   {relative info context}        info  
      |   email                            email
      |   somebool                         - - - - not implemented yet
      |   account                          account/@size
      |   number1                          number
      |   drinks                           - - - - not implemented yet
      |   phone                            phone
      |     cntr                              @cntr
      |     zone                              zone
      |     number                            number
      |
      |   ipaddress                      ipaddress
      
      |   {contacts-repeater}            contacts | each row = contact
      |     firstname                      firstname
      |     lastname                       lastname
      |     email                          email
      |     phone                          phone/@nr
       -->
  <wb:context 
    xmlns:wb="http://apache.org/cocoon/woody/binding/1.0" 
  	path="/data/wrapper/context" >
  
    <wb:context path="info">
    	<!-- the email value will not be saved because of the @readonly -->
      <wb:field id="email"   path="email"         readonly="true"/>
  		<!-- jxpath binds to nodes as well as to attributes -->
      <wb:field id="account" path="account/@size" />
      <wb:field id="number1" path="number"        />
  
  	  <!-- one entry field in the client maps through aggregate fields -->
      <wb:aggregate id="phone" path="phone" >
      	<!-- to multiple fields in the XML file -->
        <wb:field id="number" path="number" />
        <wb:field id="zone"   path="zone"   />
        <wb:field id="cntr"   path="@cntr"  />
      </wb:aggregate>
      
    </wb:context>
    
    
    <wb:field id="ipaddress" path="ipaddress" >
      <wb:on-update>
      	<!-- if the value has changed, the attribute will be set -->
        <wb:set-attribute name="changed" value="true" />
      </wb:on-update>
    </wb:field>
  
  
    <!-- repeater requires unique identification mechanism of the row-nodes -->
    <wb:repeater id="contacts"
      parent-path="contacts"
      row-path="contact"
      unique-row-id="id"
      unique-path="@id"
      >
      <!-- important note: the row-path is used inside jxpath-createPath context,
           as a consequence it cannot have dependent children or predicates -->
  
      <wb:on-bind>
      	<!-- executed on updates AND right after the insert -->
        <wb:field id="firstname" path="firstname" />
        <wb:field id="lastname"  path="lastname"  />
        <wb:field id="phone"     path="phone/@nr" />
        <wb:field id="email"     path="email"     />
      </wb:on-bind>
  
      <wb:on-delete-row>
      	<!-- chose on of these to test -->
      	<!--
        <wb:set-attribute name="row-state" value="deleted" />
        -->
        <wb:delete-node />
      </wb:on-delete-row>
  
      <wb:on-insert-row>
        <wb:insert-node>
        	<!-- template inserted by the binding for new rows (mapping new nodes) -->
          <contact id="" row-state="new">
            <firstname/><lastname/><phone nr=""/><email/>
          </contact>      	
        </wb:insert-node>
      </wb:on-insert-row>
    </wb:repeater>
  
  </wb:context>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form2_data.xml
  
  Index: form2_data.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <data><wrapper><context>
  
  	<info>
  	  <email boolBindingWorks="false">yourname@yourdomain.com</email>
      <account size="3" />
      <number>22234</number>
      <drinks>  <!-- no binding available yet -->
      	<drink>Leffe</drink>
      </drinks>
      
      <phone cntr="32">
      	<zone>2</zone>
      	<number>2222222</number>
      </phone>
  	</info>
  	
    <ipaddress changed="false">10.34.44.78</ipaddress>
  
    <contacts>
      <contact id="1" row-state="original">
      	<firstname>Lucien</firstname>
  	  	<lastname>Vandevelde</lastname>
  		  <phone nr="+32-2-2222222"/>
        <email>lv@vdvld.be</email>
      </contact>
      <contact id="2" row-state="original">
      	<firstname>Joris</firstname>
  	  	<lastname>Veldweghel</lastname>
  		  <phone nr="+32-59-595959"/>
        <email>jrsvldwghl@hotmail.com</email>
      </contact>
    </contacts>
  	
  </context></wrapper></data>
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form2_model.xml
  
  Index: form2_model.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <wd:form
    xmlns:wd="http://apache.org/cocoon/woody/definition/1.0"
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
  
    <wd:field id="email" required="true">
      <wd:datatype base="string">
        <wd:validation>
          <wd:email/>
        </wd:validation>
      </wd:datatype>
      <wd:label>Enter an <b>email</b> address:</wd:label>
    </wd:field>
  
    <wd:booleanfield id="somebool">
      <wd:label>Put me <em>on</em> or <em>off</em>.</wd:label>
    </wd:booleanfield>
  
    <wd:field id="account">
      <wd:label>Indicate the size of your bank account (in m<sup>3</sup>):</wd:label>
      <wd:datatype base="string">
        <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>
    </wd:field>
  
    <wd:field id="number1" required="true">
      <wd:label>Please enter a number:</wd:label>
      <wd:datatype base="long"/>
    </wd:field>
  
    <wd:multivaluefield id="drinks">
      <wd:label>Indicate which 2 of the following drinks you'd like to receive:</wd:label>
      <wd:datatype base="string">
        <wd:selection-list>
          <wd:item value="Maes"/>
          <wd:item value="Jupiler"/>
          <wd:item value="Leffe"/>
          <wd:item value="Hoegaarden"/>
          <wd:item value="Coca Cola"/>
        </wd:selection-list>
        <wd:validation>
          <wd:value-count exact="2"/>
        </wd:validation>
      </wd:datatype>
    </wd:multivaluefield>
  
    <wd:aggregatefield id="phone" required="true">
      <wd:label>Enter a phone number in \+([0-9]{1,3})-([0-9]{1,4})-([0-9]{5,7}) format</wd:label>
      <wd:split pattern="\+([0-9]{1,3})-([0-9]{1,4})-([0-9]{5,7})">
        <wd:map group="1" field="cntr"/>
        <wd:map group="2" field="zone"/>
        <wd:map group="3" field="number"/>
        <wd:failmessage>The phone-number format is wrong, please try again
        </wd:failmessage>
      </wd:split>
      <wd:combine expression='Concat("+", cntr, "-", zone, "-", number)'/>
      <wd:children>
        <wd:field id="cntr">
          <wd:datatype base="string"/>
        </wd:field>
        <wd:field id="zone">
          <wd:datatype base="string"/>
        </wd:field>
        <wd:field id="number">
          <wd:datatype base="string"/>
        </wd:field>
      </wd:children>
      <wd:validation>
      </wd:validation>
    </wd:aggregatefield>
  
    <wd:field id="ipaddress" required="true">
      <wd:label>Please enter your IP address</wd:label>
      <wd:datatype base="string">
        <wd:validation>
          <wd:regexp pattern="^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$">
            <wd:failmessage>Invalid IP address.</wd:failmessage>
          </wd:regexp>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:repeater id="contacts">
      <wd:field id="id">
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="firstname">
        <wd:label>Firstname</wd:label>
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="lastname">
        <wd:label>Lastname</wd:label>
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="phone">
        <wd:label>Phone</wd:label>
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="email">
        <wd:label>Email</wd:label>
        <wd:datatype base="string">
          <wd:validation>
            <wd:email/>
          </wd:validation>
        </wd:datatype>
      </wd:field>
      <wd:booleanfield id="select">
        <wd:label>Select</wd:label>
      </wd:booleanfield>
    </wd:repeater>
  
    <wd:button id="addcontact" action-command="add-contact">
      <wd:label>Add contact</wd:label>
    </wd:button>
  
    <wd:button id="removecontacts" action-command="remove-selected-contacts">
      <wd:label>Remove selected contacts</wd:label>
    </wd:button>
  
  </wd:form>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form2_template.xsp
  
  Index: form2_template.xsp
  ===================================================================
  <?xml version="1.0"?>
  <xsp:page language="java"
            xmlns:xsp="http://apache.org/xsp"
            xmlns:jpath="http://apache.org/xsp/jpath/1.0">
  <page xmlns:wt="http://apache.org/cocoon/woody/template/1.0">
    <title>Sample form</title>
    <content>
      <form method="POST">
        <xsp:attribute name="action"><xsp:expr><jpath:continuation/>+".continue"</xsp:expr></xsp:attribute>
        <table border="1">
          <tr>
            <td valign="top"><wt:widget-label id="email"/></td>
            <td valign="top"><wt:widget id="email"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="number1"/></td>
            <td valign="top"><wt:widget id="number1"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="account"/></td>
            <td valign="top"><wt:widget id="account"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="phone"/></td>
            <td valign="top"><wt:widget id="phone" /></td>
          </tr>
          <tr>
            <td/>
            <td><wt:widget id="somebool"/> <wt:widget-label id="somebool"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="drinks"/></td>
            <td valign="top"><wt:widget id="drinks"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="ipaddress"/></td>
            <td valign="top"><wt:widget id="ipaddress"/></td>
          </tr>
        </table>
  
        <wt:widget-label id="contacts"/><br/>
        <wt:repeater-size id="contacts"/>
        <table border="1">
          <tr>
            <th>(id)</th>
            <th><wt:repeater-widget-label id="contacts" widget-id="firstname"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="lastname"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="phone"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="email"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="select"/></th>
          </tr>
  
          <!-- The contents of the repeater-widget element is a template that will
          be applied to each row in the repeater. -->
          <wt:repeater-widget id="contacts">
            <tr>
              <td>[<wt:widget id="id"/>]</td>
              <td><wt:widget id="firstname"/></td>
              <td><wt:widget id="lastname"/></td>
              <td><wt:widget id="phone"/></td>
              <td><wt:widget id="email"/></td>
              <td><wt:widget id="select"/></td>
            </tr>
          </wt:repeater-widget>
  
          <tr>
            <td colspan="4" align="right">
              <wt:widget id="addcontact"/>
              <wt:widget id="removecontacts"/>
            </td>
          </tr>
        </table>
  
        <input type="submit"/>
      </form>
    </content>
  </page>
  </xsp:page>