You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2003/08/15 17:57:33 UTC

cvs commit: cocoon-2.1/src/webapp/samples/simpleform/four descriptor.xml form.xml sitemap.xmap success.xml

haul        2003/08/15 08:57:33

  Modified:    src/webapp/samples samples.xml
               src/webapp/samples/simpleform sitemap.xmap
  Added:       src/webapp/samples/simpleform samples.xml
               src/webapp/samples/simpleform/two descriptor.xml form.xml
                        sitemap.xmap success.xml
               src/webapp/samples/simpleform/three descriptor.xml form.xml
                        sitemap.xmap success.xml
               src/webapp/samples/simpleform/one ERROR.xsp OK.xsp
                        descriptor.xml sitemap.xmap
               src/webapp/samples/simpleform/four descriptor.xml form.xml
                        sitemap.xmap success.xml
  Log:
  Refactor simple form sample
  
  Revision  Changes    Path
  1.23      +5 -1      cocoon-2.1/src/webapp/samples/samples.xml
  
  Index: samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/samples.xml,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- samples.xml	10 Aug 2003 11:42:47 -0000	1.22
  +++ samples.xml	15 Aug 2003 15:57:32 -0000	1.23
  @@ -61,6 +61,10 @@
      <sample href="xsp/" name="Extensible Server Pages">
        Extensible Server Pages.
      </sample>   
  +   <sample href="simpleform/" name="Simple Forms">
  +     These examples show a simple way to work with HTML forms. More powerful
  +     form solutions can be found in the blocks section. 
  +   </sample>
       <sample href="imagereader/" name="Imagereader">
        ImageReader
      </sample> 
  
  
  
  1.5       +10 -143   cocoon-2.1/src/webapp/samples/simpleform/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/simpleform/sitemap.xmap,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sitemap.xmap	29 Jul 2003 03:15:47 -0000	1.4
  +++ sitemap.xmap	15 Aug 2003 15:57:32 -0000	1.5
  @@ -1,92 +1,6 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
   
  -<!-- ========================= Components ================================ -->
  -
  - <map:components>
  -  <map:generators default="file"/>
  -
  -  <map:transformers default="xslt">
  -
  -   <!-- This transformer is used to extract the form instance data from the xml document. See
  -        the javadocs of this class for more information on the default configuration and 
  -        configuration options.
  -        The instance data is stored as an attribute with the same name as the form using an
  -        output module. Here we decide to use the RequestAttributeMap module. This would allows
  -        a) to store instances for several forms and b) to access a particular instance and value
  -        using JXPath syntax.
  -        Per default, the map key is the name of the form as is the root node of the new Document.
  -    -->
  -   <map:transformer name="sfinstance" 
  -                    logger="sitemap.transformer.simpleform" 
  -                    src="org.apache.cocoon.transformation.SimpleFormInstanceExtractionTransformer">
  -       <output name="request-attr-map"/>
  -   </map:transformer>
  -
  -   <!-- the SimpleFormTransformer acts upon HTML4 form element tags and replaces their
  -        value attribute or their content in case of the textarea element with data obtained
  -        from an input module attribute with the same name. In addition, it checks the result 
  -        of the FormValidatorAction when it encounters <error/> tags and includes / excludes
  -        them depending on the result. 
  -
  -        While many configuration options are available at run time, the input module has
  -        to be configured at declaration time. Thus a second instance of the SimpleFormTransformer
  -        is needed.
  -
  -        How is the instance data accessed?
  -        If the user submitted data, those parameters shall be used, otherwise,
  -        it is stored as Document (DOM) in a Map that is stored in a request attribute.
  -        Thus, first a request attribute is read, passing a fixed attribute name because the name 
  -        of the map is fixed. This is the default name for attributes set by the RequestAttributeMap
  -        module.
  -        Next, a JXPath expression is applied to this map. The expression is the name attribute of the
  -        HTML form tag currently transformed! Since both map key and root node is the same (here: "person"),
  -        and we don't want to reflect this in our HTML form, the simplemap input module is used to
  -        prepend the string "/person/" to the jxpath expression.
  -    -->
  -   <map:transformer name="simpleform" 
  -                    logger="sitemap.transformer.simpleform" 
  -                    src="org.apache.cocoon.transformation.SimpleFormTransformer">
  -    <input-module name="chain">
  -       <input-module name="request-param"/>
  -       <input-module name="simplemap">
  -          <prefix>/person/</prefix>
  -          <input-module name="jxpath">
  -            <!-- "jxpath" does not pass the attribute name to the module it
  -                 obtains the value to act from. Thus an additional attribute
  -                 name needs to be injected. 
  -            -->
  -            <from-parameter>org.apache.cocoon.components.modules.output.OutputModule</from-parameter>
  -            <input-module name="request-attr"/>
  -          </input-module>
  -       </input-module>
  -    </input-module>
  -   </map:transformer>
  -   
  -  </map:transformers>
  -  
  -  
  -  <map:readers default="resource"/>
  -  <map:serializers default="html"/>
  -  <map:matchers default="wildcard"/>
  -  <map:selectors default="browser"/>
  - </map:components>
  -
  -<!-- =========================== Resources ================================= -->
  -
  - <map:resources>
  -  <map:resource name="dynamic-page">
  -     <map:generate src="{target}.xsp" type="serverpages"/>
  -     <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
  -        <map:parameter name="servletPath" value="{request:servletPath}"/>
  -        <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
  -        <map:parameter name="contextPath" value="{request:contextPath}"/>
  -        <map:parameter name="file" value="{target}.xsp"/>
  -        <map:parameter name="remove" value="{remove}"/>
  -     </map:transform>
  -     <map:serialize/>
  -  </map:resource>
  - </map:resources>
   
   <!-- =========================== Views =================================== -->
   
  @@ -113,67 +27,20 @@
     <map:pipeline>
   
      <map:match pattern="">
  -     <map:redirect-to uri="sform"/>
  +     <map:redirect-to uri="samples"/>
      </map:match>
  -   
  -   <!-- ============ form validation using xsp and logicsheet ============== -->
   
  -   <map:match pattern="formval">
  -     <map:act type="form-validator">
  -        <map:parameter name="descriptor" value="descriptor.xml"/>
  -        <map:parameter name="validate-set" value="car-reservation"/>
  -        <map:call resource="dynamic-page">
  -           <map:parameter name="target" value="OK"/>
  -           <map:parameter name="remove" value="{../0}"/>
  -        </map:call>
  -     </map:act>
  -     <map:call resource="dynamic-page">
  -        <map:parameter name="target" value="ERROR"/>
  -        <map:parameter name="remove" value="{0}"/>
  -     </map:call>
  +   <map:match pattern="samples">
  +    <map:generate src="samples.xml"/>
  +    <map:transform src="context://samples/common/style/xsl/html/simple-samples2html.xsl">
  +       <map:parameter name="contextPath" value="{request:contextPath}"/>
  +    </map:transform>
  +    <map:serialize/>
      </map:match>
   
  -
  -   <!-- ============ form validation using transformers ======================== -->
  -
  -   <map:match pattern="*">
  -
  -    <!-- Check the request parameters using the FormValidatorAction -->
  -    <map:act type="form-validator">
  -      <!-- parameters to the action -->
  -      <!-- file that contains the validation rules and rule sets -->
  -      <map:parameter name="descriptor" value="descriptor.xml"/>
  -      <!-- rule set to use -->
  -      <map:parameter name="validate-set" value="testform"/>
  -      
  -      <!-- this is only applied if the validation has been successful -->
  -      <map:generate src="success.xml"/>
  -      <map:transform type="simpleform"/>
  -      <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
  -         <map:parameter name="servletPath" value="{request:servletPath}"/>
  -         <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
  -         <map:parameter name="contextPath" value="{request:contextPath}"/>
  -         <map:parameter name="file" value=".xml"/>
  -      </map:transform>
  -      <map:serialize/>
  -      <!-- because of the above serializer the "success" pipeline ends here. -->
  -
  -    </map:act>
  -    <!-- continue processing -->
  -    <!-- since the "success" pipeline ends with a serializer, the following is only 
  -         applied if validation has not been successful.
  -     -->
  -
  -    <map:generate type="file" src="{1}.xml"/>    
  -    <map:transform type="sfinstance"/> <!-- extract the instance data -->
  -    <map:transform type="simpleform"/><!-- fill in the instance data, request parameters, and error tags -->
  -     <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
  -        <map:parameter name="servletPath" value="{request:servletPath}"/>
  -        <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
  -        <map:parameter name="contextPath" value="{request:contextPath}"/>
  -        <map:parameter name="file" value=".xml"/>
  -     </map:transform>
  -    <map:serialize/>
  +   <!-- samples automount -->  
  +   <map:match pattern="*/**">
  +     <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
      </map:match>
           
     </map:pipeline>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/samples.xml
  
  Index: samples.xml
  ===================================================================
  <?xml version="1.0" encoding="iso-8859-1"?>
  
  <!-- CVS: $Id: samples.xml,v 1.1 2003/08/15 15:57:32 haul Exp $ -->
  
  <samples xmlns:xlink="http://www.w3.org/1999/xlink" name="simple form handling">
  
    <group name="Simple Form Handling">
       <note>
         This samples group demonstrates the use for the simple form handling
         in Apache Cocoon. Simple form handling consists of four parts:
         validating user input, filling forms with submitted data, displaying 
         validation results, and filling forms with default values. This
         corresponds largely to the involved Cocoon components: a validating
         action, a logicsheet helping to display validation results, a
         transformer to fill in submitted data and display validation results,
         and a transformer to extract default values.
       </note>
       <note>
         Apache Cocoon contains several approaches to forms. The one demonstrated
         here is probably the simplest but also the weakest. Please do consider
         the others as well: JXForms and Woody.
       </note>
       <sample name="Logicsheet" href="one/index">
         On a XSP two logicsheets are used to redisplay submitted data and
         indicate validation results.
       </sample>
       <sample name="One Transformer" href="two/index">
         On a static XML page a form is displayed, submitted data is filled in,
         and validation results are displayed by the use of the
         SimpleFormTransformer.
       </sample>
       <sample name="Default Values" href="three/index">
         On a static XML page, form elements are separated from the default
         values. The SimpleFormInstanceTransformer is used to extract the data
         and the SimpleFormTransformer is used to pre-fill the form. No
         validation is performed.
       </sample>
       <sample name="Transformer Sample" href="four/index">
         This sample combines the two samples above into one.
       </sample>
    </group>
    
  </samples>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/two/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
  
     <parameter name="persons" type="long" min="2" max="9" default="5" nullable="yes"/>
     <parameter name="deposit" type="double" min="10.0" max="999.99"/>
     <parameter name="email" type="string" max-len="50" matches-regex="^[\d\w][\d\w\-_\.]*@([\d\w\-_]+\.)+\w\w\w?$"/>
     <parameter name="address" type="string" min-len="10" max-len="200" nullable="no"/>
     <parameter name="type" type="string" nullable="no" one-of="|cabrio|sedan|station|racing|"/>
  
     <constraint-set name="car-reservation">
         <validate name="persons"/>
         <validate name="deposit" min="50.0"/>
         <validate name="email"/>
         <validate name="address"/>
         <validate name="type"/>
      </constraint-set>
  
  </root>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/two/form.xml
  
  Index: form.xml
  ===================================================================
  <?xml version="1.0"?>
  <page>
  <head>
  <style type="text/css">
  error {
  	font-style:italic;
  	font-weight:bold;
  	color:red;
  	background-color:#fffbe4;
  	display: block;
  }
  </style>
  </head>
  	<body>
  		<h1>Reserve a car with Cocoon Cars!</h1>
  
  		<p>This sample illustrates how to use simple form validation in conjunction
  		with the SimpleFormTransformer to fill in user submitted data.</p>
  
  		<h2>Car Reservation</h2>
  		<p>Please fill in the form completely in order to reserve a car.</p>
  		<form name="car" method="post">
  			<table>
  				<tbody>
  					<tr>
  						<td>
              	           The car should seat
  						   <select size="1" name="persons">
  							<option value="" selected="true" disabled="true">Please select</option>
  						   	<option value="2">2</option>
  						   	<option value="4">4</option>
  						   	<option value="5">5</option>
  						   	<option value="7">7</option>
  						   	<option value="9">9</option>
  						   </select>
  						   Persons.
  						</td>
  						<td>
  							<error name="persons" when-ge="error">*</error>
  						</td>
  					</tr>
  					<tr>
  						<td>
  							The car should by a
  							<select size="1" name="type">
  							<option value="" selected="true" disabled="true">Please select</option>
  							<option value="sedan">Sedan Car</option>
  							<option value="station">Station Wagon</option>
  							<option value="cabrio">Cabrio</option>
  							<option value="racing">Sports Car</option>
  							</select>
  						</td>
  						<td><error name="type" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>
  							I'd like to deposit EUR <input type="text" size="4" name="deposit"/>
  						</td>
  						<td><error name="deposit" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>My email is <input type="text" size="30" name="email"/></td>
  						<td><error name="email" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>
  							Please bill to
  							<textarea name="address" cols="30" rows="5" />
  						</td>
  						<td><error name="address" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td colspan="2">
  							<error name="*" when-ge="error">An error occurred. Please check your input and the messages below for more information.</error>
  							<error name="persons" when="too-small">The smallest car seats 2.</error>
  							<error name="persons" when="too-large">The largest car seats 9.</error>
  							<error name="deposit" when="too-small">The deposit needs to be at least EUR 50.</error>
  							<error name="deposit" when="is-null">Please specify a deposit.</error>
  							<error name="email" when="is-null">Please fill in an email address.</error>
  							<error name="email" when="no-match">Your email seems incorrect. Please fill in a correct email address.</error>
  							<error name="address" when="is-null">Please fill in a billing address.</error>
  							<error name="address" when="too-small">Your address seems to be incorrect. Please fill in a correct billing address.</error>
  							<error name="type" when="is-null">Please select the type of car you would like to drive.</error>
  							<error name="type" when="no-match">Please select one of the existing type of car.</error>
  						</td>
  					</tr>
  					<tr>
  						<td></td>
  						<td><input type="submit" name="go" value="go!"/></td>
  					</tr>
  				</tbody>
  			</table>
  		</form>
  	</body>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/two/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  
   <map:components>
  
    <!--+
        | In order to use simple form validation, we need to make this action
        | available to the sitemap. Components are inherited, so this could have
        | been done in a parent sitemap. However, to illustrate the usage, we
        | do it here.
        |
        | Note, there are several different validator actions available in
        | Cocoon. They share the same validation code but operate on different
        | values. Here, we're interested in validating request parameters, thus
        | the FormValidatorAction is the right choice.
        |
        | The action is the only component we need to declare - the logicsheet
        | has been added to cocoon.xconf for you already.
        +-->
    <map:actions>
     <map:action name="formval" 
          	   logger="sitemap.action.form-validator" 
          	   src="org.apache.cocoon.acting.FormValidatorAction"/>
    </map:actions>
  
  
  
    <!--+
        | Validation should only occurr when data has been submitted. Therefore
        | a selector is created that will be used to select upon the request method.
        | This is optional if you don't mind to show validation results without
        | user input.
        |
        +-->
    <map:selectors>
      <map:selector name="simple"
                   logger="sitemap.matcher.wildcard"
                   src="org.apache.cocoon.selection.SimpleSelector"/>
    </map:selectors>
  
  
  
    <!--+ the SimpleFormTransformer acts upon HTML4 form element tags and replaces their
        | value attribute or their content in case of the textarea element with data obtained
        | from an input module attribute with the same name. In addition, it checks the result 
        | of the FormValidatorAction when it encounters <error/> tags and includes / excludes
        | them depending on the result. 
        |
        +-->
    <map:transformers default="xslt">
     <map:transformer name="simpleform" 
                      logger="sitemap.transformer.simpleform" 
                      src="org.apache.cocoon.transformation.SimpleFormTransformer">
        <input-module name="request-param"/>
     </map:transformer>
     
    </map:transformers>
    
   </map:components>
  
  <!--+
      | This is a standard resource for rendering a XSP page.
      +-->
   <map:resources>
    <map:resource name="static-page">
        <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
           <map:parameter name="servletPath" value="{request:servletPath}"/>
           <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
           <map:parameter name="contextPath" value="{request:contextPath}"/>
           <map:parameter name="remove" value="{/0}"/>
           <map:parameter name="file" value="{file}.xml"/>
        </map:transform>
        <map:serialize/>
    </map:resource>
   </map:resources>
  
  <!--+
      | These views provide different 'standard' views to the samples.
      |
      +-->
  
   <map:views>
    <map:view name="content" from-label="content">
     <map:serialize type="xml"/>
    </map:view>
  
    <map:view from-label="content" name="pretty-content">
      <map:transform src="context://stylesheets/system/xml2html.xsl"/>
      <map:serialize type="html"/>
    </map:view>
    
    <map:view name="links" from-position="last">
     <map:serialize type="links"/>
    </map:view>
  
   </map:views>
  
  
  <!--+
      | Pipelines
      |
      +-->
  
  
   <map:pipelines>
  
    <map:pipeline>
  
  
     <!-- some redirections -->
     <map:match pattern="">
       <map:redirect-to uri="index"/>
     </map:match>
     
  
  
     <map:match pattern="index">
      <!--+
          | Only validate when data was submitted
          +-->
      <map:select type="simple">
         <map:parameter name="value" value="{request:method}"/>
         <map:when test="POST">
         	  <!--+
         	      | Check the request parameters using the FormValidatorAction 
         	      +-->
         	  <map:act type="formval">
         	    <map:parameter name="descriptor" value="descriptor.xml"/>
         	    <map:parameter name="validate-set" value="car-reservation"/>
         	    <!--+
         	        | this is the success case
         	        |
         	        +-->
         	    <map:generate src="success.xml"/>
         	    <map:transform type="simpleform"/>
      		<map:call resource="static-page">
      		  <map:parameter name="file" value="success"/>
      		</map:call>
         	    <!-- because of the resource above the "success" pipeline ends here. -->
         	  </map:act>
         </map:when>
       </map:select>
       <!--+
           | this branch contains the failed validation.
           | Since the "success" pipeline ends with a resource, the following is only 
           | applied if validation has not been successful.
           |
           +-->
      <map:generate type="file" src="form.xml"/>    
      <!--+
          | fill in the request parameters, and error tags 
          +-->
      <map:transform type="simpleform"/>
      <map:call resource="static-page">
        <map:parameter name="file" value="form"/>
      </map:call>
     </map:match>
  
  
  
     <!-- some redirections -->
     <map:match pattern="*">
       <map:redirect-to uri="index"/>
     </map:match>
          
    </map:pipeline>
   </map:pipelines>
  
  </map:sitemap>
  
  <!-- end of file -->
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/two/success.xml
  
  Index: success.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <page>
    <title>Formvalidation and -prefilling</title>
    <content>
  
      <para>
        The entered data successfully passed the validation stage.
      </para>
  
  
      <form name="car" method="post">
         <para>
           A <input type="text" name="type" readonly="true"/> car which seats
  		 <input type="text" name="persons" readonly="true"/> has been reserved for you.
           Please leave the deposit of EUR <input type="text" name="deposit" readonly="true"/>
  		 at the reception. The invoice will be send to <textarea name="address"/> and a
  		 confirmation email will be send to <input type="text" readonly="true" name="email"/>. Thank you.
         </para>
      </form>
  
    </content>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/three/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
  
     <parameter name="persons" type="long" min="2" max="9" default="5" nullable="yes"/>
     <parameter name="deposit" type="double" min="10.0" max="999.99"/>
     <parameter name="email" type="string" max-len="50" matches-regex="^[\d\w][\d\w\-_\.]*@([\d\w\-_]+\.)+\w\w\w?$"/>
     <parameter name="address" type="string" min-len="10" max-len="200" nullable="no"/>
     <parameter name="type" type="string" nullable="no" one-of="|cabrio|sedan|station|racing|"/>
  
     <constraint-set name="car-reservation">
         <validate name="persons"/>
         <validate name="deposit" min="50.0"/>
         <validate name="email"/>
         <validate name="address"/>
         <validate name="type"/>
      </constraint-set>
  
  </root>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/three/form.xml
  
  Index: form.xml
  ===================================================================
  <?xml version="1.0"?>
  <page>
  <head>
  <style type="text/css">
  error {
  	font-style:italic;
  	font-weight:bold;
  	color:red;
  	background-color:#fffbe4;
  	display: block;
  }
  </style>
  </head>
  	<body>
  		<h1>Reserve a car with Cocoon Cars!</h1>
  
  		<p>Here, only default data that is provided separate from the form
             elements is filled in. No validation occurrs. The transformer has
             been instructed to let error elements pass, therefore all errors
             are shown.</p>
  
  		<h2>Car Reservation</h2>
  		<p>Please fill in the form completely in order to reserve a car.</p>
  		<form name="car" method="post">
              <!-- the transformer can be configured to look for the instance -->
              <!-- data outside the form element. -->
              <form-instance>
                  <persons>4</persons>
                  <deposit>50</deposit>
                  <email>your email</email>
                  <address>Please
  fill in your
  address.
                  </address>
                  <type>sedan</type>
              </form-instance>
  			<table>
  				<tbody>
  					<tr>
  						<td>
              	           The car should seat
  						   <select size="1" name="persons">
  							<option value="" selected="true" disabled="true">Please select</option>
  						   	<option value="2">2</option>
  						   	<option value="4">4</option>
  						   	<option value="5">5</option>
  						   	<option value="7">7</option>
  						   	<option value="9">9</option>
  						   </select>
  						   Persons.
  						</td>
  						<td>
  							<error name="persons" when-ge="error">*</error>
  						</td>
  					</tr>
  					<tr>
  						<td>
  							The car should by a
  							<select size="1" name="type">
  							<option value="" selected="true" disabled="true">Please select</option>
  							<option value="sedan">Sedan Car</option>
  							<option value="station">Station Wagon</option>
  							<option value="cabrio">Cabrio</option>
  							<option value="racing">Sports Car</option>
  							</select>
  						</td>
  						<td><error name="type" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>
  							I'd like to deposit EUR <input type="text" size="4" name="deposit"/>
  						</td>
  						<td><error name="deposit" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>My email is <input type="text" size="30" name="email"/></td>
  						<td><error name="email" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>
  							Please bill to
  							<textarea name="address" cols="30" rows="5" />
  						</td>
  						<td><error name="address" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td colspan="2">
  							<error name="*" when-ge="error">An error occurred. Please check your input and the messages below for more information.</error>
  							<error name="persons" when="too-small">The smallest car seats 2.</error>
  							<error name="persons" when="too-large">The largest car seats 9.</error>
  							<error name="deposit" when="too-small">The deposit needs to be at least EUR 50.</error>
  							<error name="deposit" when="is-null">Please specify a deposit.</error>
  							<error name="email" when="is-null">Please fill in an email address.</error>
  							<error name="email" when="no-match">Your email seems incorrect. Please fill in a correct email address.</error>
  							<error name="address" when="is-null">Please fill in a billing address.</error>
  							<error name="address" when="too-small">Your address seems to be incorrect. Please fill in a correct billing address.</error>
  							<error name="type" when="is-null">Please select the type of car you would like to drive.</error>
  							<error name="type" when="no-match">Please select one of the existing type of car.</error>
  						</td>
  					</tr>
  					<tr>
  						<td></td>
  						<td><input type="submit" name="go" value="go!"/></td>
  					</tr>
  				</tbody>
  			</table>
  		</form>
  	</body>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/three/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  
   <map:components>
  
  
    <map:transformers default="xslt">
     <!--+ 
         | This transformer is used to extract the form instance data from the
         | xml document. See the javadocs of this class for more information on
         | the default configuration and  configuration options.
         |
         | Here, the instance data is nested inside the form element. The
         | transformer can be configured to look for it at other places.
         |
         | The instance data is stored as an attribute with the same name as the 
         | form using an output module. Here we decide to use the RequestAttributeMap
         |  module. This would allows
         | a) to store instances for several forms and 
         | b) to access a particular instance and value using JXPath syntax.
         |
         | Per default, the map key is the name of the form as is the root node 
         | of the new Document.
         |
         +-->
     <map:transformer name="sfinstance" 
                      logger="sitemap.transformer.simpleform-request" 
                      src="org.apache.cocoon.transformation.SimpleFormInstanceExtractionTransformer">
       <output name="request-attr-map"/>
     </map:transformer>
  
     <!--+ 
         | This is the other transformer to read and insert the instance data. 
         | It will be applied first in the pipeline so that the user submitted 
         | data can override the default data. 
         |
         | Only one of the two transformers needs to check for validation errors, 
         | this instance has been instructed to ignore validation results because 
         | looking up the instance data requires to augment the element name with
         | the form name and thus differ from the validation result names.
  	   |
         | The instance extractor places the form instances into a map with the 
         | form name as key. Furthermore, it has been instructed to create a root
         |  element wrapping the instance data with the same name as the form. 
         | Hence we need to included the form's name twice in the element name 
         | used for the lookup.
  	   |
         | In addition, we may want to be able to select from a XSP if the form 
         | data should be replaced with values from the instance or from the 
         | request. Therefore, a different attribute is used to protect element 
         | values.
         |
         +-->
     <map:transformer name="simpleform-instance" 
                      logger="sitemap.transformer.simpleform-instance" 
                      src="org.apache.cocoon.transformation.SimpleFormTransformer">
       <fixed-attribute>this-is-never-used</fixed-attribute>
       <use-form-name-twice>true</use-form-name-twice>
       <ignore-validation>true</ignore-validation>
       <input-module name="jxpath">
         <!--+
             | "jxpath" does not pass the attribute name to the module it
             | obtains the value to act from. Thus an additional attribute
             | name needs to be injected. 
             +-->
         <from-parameter>org.apache.cocoon.components.modules.output.OutputModule</from-parameter>
         <input-module name="request-attr"/>
       </input-module>
        </map:transformer>
  
     
    </map:transformers>
    
   </map:components>
  
  <!--+
      | This is a standard resource for rendering a XSP page.
      +-->
   <map:resources>
    <map:resource name="static-page">
        <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
           <map:parameter name="servletPath" value="{request:servletPath}"/>
           <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
           <map:parameter name="contextPath" value="{request:contextPath}"/>
           <map:parameter name="remove" value="{/0}"/>
           <map:parameter name="file" value="{file}.xml"/>
        </map:transform>
        <map:serialize/>
    </map:resource>
   </map:resources>
  
  <!--+
      | These views provide different 'standard' views to the samples.
      |
      +-->
  
   <map:views>
    <map:view name="content" from-label="content">
     <map:serialize type="xml"/>
    </map:view>
  
    <map:view from-label="content" name="pretty-content">
      <map:transform src="context://stylesheets/system/xml2html.xsl"/>
      <map:serialize type="html"/>
    </map:view>
    
    <map:view name="links" from-position="last">
     <map:serialize type="links"/>
    </map:view>
  
   </map:views>
  
  
  <!--+
      | Pipelines
      |
      +-->
  
  
   <map:pipelines>
  
    <map:pipeline>
  
  
     <!-- some redirections -->
     <map:match pattern="">
       <map:redirect-to uri="index"/>
     </map:match>
     
  
  
     <map:match pattern="index">
       <!--+
           | this branch contains the failed validation.
           | Since the "success" pipeline ends with a resource, the following is only 
           | applied if validation has not been successful.
           |
           +-->
      <map:generate type="file" src="form.xml"/>    
      <!--+
          | extract the instance data
          +-->
      <map:transform type="sfinstance"/>
      <!--+
          | fill in the instance data 
          +-->
      <map:transform type="simpleform-instance"/>
      <map:call resource="static-page">
        <map:parameter name="file" value="form"/>
      </map:call>
     </map:match>
  
  
  
     <!-- some redirections -->
     <map:match pattern="*">
       <map:redirect-to uri="index"/>
     </map:match>
          
    </map:pipeline>
   </map:pipelines>
  
  </map:sitemap>
  
  <!-- end of file -->
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/three/success.xml
  
  Index: success.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <page>
    <title>Formvalidation and -prefilling</title>
    <content>
  
      <para>
        The entered data successfully passed the validation stage.
      </para>
  
  
      <form name="car" method="post">
         <para>
           A <input type="text" name="type" readonly="true"/> car which seats
  		 <input type="text" name="persons" readonly="true"/> has been reserved for you.
           Please leave the deposit of EUR <input type="text" name="deposit" readonly="true"/>
  		 at the reception. The invoice will be send to <textarea name="address"/> and a
  		 confirmation email will be send to <input type="text" readonly="true" name="email"/>. Thank you.
         </para>
      </form>
  
    </content>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/one/ERROR.xsp
  
  Index: ERROR.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  
  <xsp:page language="java"
            xmlns:xsp="http://apache.org/xsp"
            xmlns:xsp-formval="http://apache.org/xsp/form-validator/2.0"
            xmlns:xsp-request="http://apache.org/xsp/request/2.0">
  
     <page>
  
      <resources>
         <resource type="file" href="descriptor.xml">Descriptor</resource>
         <resource type="doc" href="userdocs/xsp/logicsheet-forms.html">Action &amp; Logicsheet</resource>
      </resources>
  
      <title>Car Reservation</title>
      <content>
  
      <para>
         Informal validation results <xsp:expr><xsp-formval:results/></xsp:expr>
      </para>
  
      <form method="POST">
       <!-- use this to get a clue if the user had a chance to fill in
            any date already. This is necessary if no validation results should be
            displayed when the user first encounters the form. If the error messages
            should be used to guide the user from the beginning, this is not needed.
        -->
       <input type="hidden" name="visited" value="true"/>
       <xsp:logic>
          boolean userHasSeenForm = (<xsp-request:get-parameter name="visited"/>!=null);
       </xsp:logic>
  
  
  
       <!-- if validation constraints should be included in the error messages, a
            reference to the file containing the validation rules is needed. Otherwise
            it can be removed.
       -->
       <xsp-formval:descriptor name="descriptor.xml" constraint-set="car-reservation">
  
        <table>
         <tbody>
  
          <!-- the first example field illustrates the simplest usage, passing the current
               validation field name every time.
          -->
          <tr>
           <td>How many persons should the car seat?</td>
           <td>
            <input type="TEXT" name="persons" size="2">
             <xsp:attribute name="value"><xsp-request:get-parameter name="persons" default=""/></xsp:attribute>
            </input>
           </td>
           <td>
            <xsp:logic>
              if (userHasSeenForm) {
                if (<xsp-formval:is-toosmall name="persons"/> ) {
                   <b> The smallest available car seats <xsp-formval:get-attribute parameter="persons" name="min"/></b>
                } else if ( <xsp-formval:is-toolarge name="persons"/> ) {
                   <b> The largest available car seats <xsp-formval:get-attribute parameter="persons" name="max"/></b>
                } else if (<xsp-formval:is-error name="persons"/> ) {
                   <b> Some error occured. Your input is not correct. </b>
                }
              }
            </xsp:logic>
           </td>
          </tr>
  
  
          <!-- another possibility is to create a context that is used for all nested 
               validation tags. Note that here no validation parameter name is added to
               the validation tags.
          -->
          <xsp-formval:validate name="deposit">
           <tr>
            <td>Please enter your deposit EUR</td>
            <td>
             <input type="TEXT" name="deposit" size="10">
              <xsp:attribute name="value"><xsp-request:get-parameter name="deposit" default=""/></xsp:attribute>
             </input>
            </td>
            <td>
             <xsp:logic>
              if (userHasSeenForm) {
                if ( <xsp-formval:is-null/>) {
                   <b> You need to specify a deposit </b>
                } else if ( <xsp-formval:is-toosmall/> ) {
                   <b> The deposit has to be at least EUR <xsp-formval:get-attribute name="min"/></b>
                } else if ( <xsp-formval:is-toolarge/> ) {
                   <b> The deposit has to be at most EUR <xsp-formval:get-attribute name="max"/></b>
                } else if (<xsp-formval:is-notpresent/> ) {
                   <b></b>
                } else if ( <xsp-formval:is-error/>) {
                   <b> Some error occured. Your input is not correct. </b>
                }
              }
             </xsp:logic>
            </td>
           </tr>
          </xsp-formval:validate>
  
          <xsp-formval:validate name="email">
           <tr>
            <td>Please enter your email</td>
            <td>
             <input type="TEXT" name="email" size="50">
              <xsp:attribute name="value"><xsp-request:get-parameter name="email" default=""/></xsp:attribute>
             </input>
            </td>
            <td>
             <xsp:logic>
              if (userHasSeenForm) {
                 if ( <xsp-formval:is-null/>) {
                    <b> You need to specify an email </b>
                 } else if ( <xsp-formval:is-nomatch/> ) {
                    <b> This does not seem to be a valid email
                        address. Expected 
                        <pre><xsp-formval:get-attribute parameter="email" name="matches-regex"/></pre>
                    </b>
                 } else if ( <xsp-formval:is-toolarge/> ) {
                    <b> Only addresses with up to 
                        <xsp-formval:get-attribute parameter="email" name="max-len"/> 
                        characters are accepted
                    </b>
                 } else if (<xsp-formval:is-notpresent/> ) {
                    <b></b>
                 } else if ( <xsp-formval:is-error/>) {
                    <b> Some error occured. Your input is not correct. </b>
                 }
              }
             </xsp:logic>
            </td>
           </tr>
          </xsp-formval:validate>
  
  
          <!-- less embedded java is needed when using the <xsp-formval:on-XXX/> tags. They are
               equivalent to the above "<xsp:logic>if (<xsp-formval:is-XXX/>) { ... } </xsp:logic>"
               but much cleaner. 
          -->
          <xsp-formval:validate name="address">
           <tr>
            <td>Please enter the billing address</td>
            <td>
             <textarea rows="6" cols="40" name="address"><xsp-request:get-parameter name="address" default=""/></textarea>
            </td>
            <td>
             <xsp:logic>
              if (userHasSeenForm) {
                 <xsp-formval:on-null>
                   <b> You need to specify an address. </b>
                 </xsp-formval:on-null>
  
                 <xsp-formval:on-toolarge>
                   <b> Only addresses with up to 
                       <xsp-formval:get-attribute parameter="address" name="max-len"/> 
                       characters are accepted.
                   </b>
                 </xsp-formval:on-toolarge>
  
                 <xsp-formval:on-notpresent/>
              
                 <xsp-formval:on-error>
                   <b> Some error occured. Your input is not correct. </b>
                 </xsp-formval:on-error>
              }
             </xsp:logic>
            </td>
           </tr>
          </xsp-formval:validate>
  
  
          <xsp-formval:validate name="type">
           <tr>
            <td>Please enter the type of car you would like to reserve</td>
            <td>
             <input type="text" name="type" size="10">
                <xsp:attribute name="value"><xsp-request:get-parameter name="type" default=""/></xsp:attribute>
             </input>
            </td>
            <td>
             <xsp:logic>
              if (userHasSeenForm) {
                 <xsp-formval:on-null>
                   <b> You need to specify a type: cabrio, sedan, station, racing. </b>
                 </xsp-formval:on-null>
  
                 <xsp-formval:on-nomatch>
                   <b> Only <xsp-formval:get-attribute parameter="type" name="one-of"/> 
                       are accepted.
                   </b>
                 </xsp-formval:on-nomatch>
  
                 <xsp-formval:on-notpresent/>
              
                 <xsp-formval:on-error>
                   <b> Some error occured. Your input is not correct. </b>
                 </xsp-formval:on-error>
              }
             </xsp:logic>
            </td>
           </tr>
          </xsp-formval:validate>
         </tbody>
        </table>
           
       </xsp-formval:descriptor>
       <input type="submit" name="submit" value="submit"/>
      </form>
  
     </content>
    </page>
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/one/OK.xsp
  
  Index: OK.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp"
     xmlns:xsp-formval="http://apache.org/xsp/form-validator/2.0"
     xmlns:xsp-request="http://apache.org/xsp/request/2.0"
  >
  
     <page>
      <resources>
         <resource type="file" href="descriptor.xml">Descriptor</resource>
         <resource type="doc" href="userdocs/xsp/logicsheet-forms.html">Action &amp; Logicsheet</resource>
      </resources>
  
        <title>Car Reservation</title>
        <content>
  
        <para>You've successfully reserved a <b><xsp-request:get-parameter name="type"/></b> car for
        <b><xsp-request:get-parameter name="persons"/></b> with a deposit of
        <b>EUR <xsp-request:get-parameter name="deposit"/></b>.</para> 
  
        <para> Details will be sent to your e-mail address
        <tt><xsp-request:get-parameter name="email"/></tt></para>
  
        <para> The bill will be sent to <pre>
  <xsp-request:get-parameter name="address"/></pre></para>
  
        <para>You can make a new reservation <a href="formval">here</a></para>
  
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/one/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
  
     <parameter name="persons" type="long" min="2" default="9" nullable="yes"/>
     <parameter name="deposit" type="double" min="10.0" max="999.99"/>
     <parameter name="email" type="string" max-len="50" matches-regex="^[\d\w][\d\w\-_\.]*@([\d\w\-_]+\.)+\w\w\w?$"/>
     <parameter name="address" type="string" min-len="10" max-len="200" nullable="no"/>
     <parameter name="type" type="string" nullable="no" one-of="|cabrio|sedan|station|racing|"/>
  
     <constraint-set name="car-reservation">
         <validate name="persons"/>
         <validate name="deposit" min="50.0"/>
         <validate name="email"/>
         <validate name="address"/>
         <validate name="type"/>
      </constraint-set>
  
  </root>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/one/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  
   <map:components>
  
    <!--+
        | In order to use simple form validation, we need to make this action
        | available to the sitemap. Components are inherited, so this could have
        | been done in a parent sitemap. However, to illustrate the usage, we
        | do it here.
        |
        | Note, there are several different validator actions available in
        | Cocoon. They share the same validation code but operate on different
        | values. Here, we're interested in validating request parameters, thus
        | the FormValidatorAction is the right choice.
        |
        | The action is the only component we need to declare - the logicsheet
        | has been added to cocoon.xconf for you already.
        +-->
    <map:actions>
     <map:action name="formval" 
          	   logger="sitemap.action.form-validator" 
          	   src="org.apache.cocoon.acting.FormValidatorAction"/>
    </map:actions>
  
   </map:components>
  
  <!--+
      | This is a standard resource for rendering a XSP page.
      +-->
  
   <map:resources>
    <map:resource name="dynamic-page">
       <map:generate src="{target}.xsp" type="serverpages"/>
       <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
          <map:parameter name="servletPath" value="{request:servletPath}"/>
          <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
          <map:parameter name="contextPath" value="{request:contextPath}"/>
          <map:parameter name="file" value="{target}.xsp"/>
          <map:parameter name="remove" value="{remove}"/>
       </map:transform>
       <map:serialize/>
    </map:resource>
   </map:resources>
  
  <!--+
      | These views provide different 'standard' views to the samples.
      |
      +-->
  
   <map:views>
    <map:view name="content" from-label="content">
     <map:serialize type="xml"/>
    </map:view>
  
    <map:view from-label="content" name="pretty-content">
      <map:transform src="context://stylesheets/system/xml2html.xsl"/>
      <map:serialize type="html"/>
    </map:view>
    
    <map:view name="links" from-position="last">
     <map:serialize type="links"/>
    </map:view>
  
   </map:views>
  
  
  <!--+
      | Pipelines
      |
      +-->
  
   <map:pipelines>
  
    <map:pipeline>
  
     <!-- some redirections -->
     <map:match pattern="">
       <map:redirect-to uri="index"/>
     </map:match>
     
  
  
     <map:match pattern="index">
       <map:act type="formval">
          <map:parameter name="descriptor" value="descriptor.xml"/>
          <map:parameter name="validate-set" value="car-reservation"/>
          <!--+
              | this is the success case
              +-->
          <map:call resource="dynamic-page">
             <map:parameter name="target" value="OK"/>
             <map:parameter name="remove" value="{../0}"/>
          </map:call>
       </map:act>
       <!--+
           | this branch contains the failed validation.
           | Since the "success" pipeline ends with a serializer, the following is only 
           | applied if validation has not been successful.
           |
           +-->
       <map:call resource="dynamic-page">
          <map:parameter name="target" value="ERROR"/>
          <map:parameter name="remove" value="{0}"/>
       </map:call>
     </map:match>
  
  
  
     <!-- some redirections -->
     <map:match pattern="*">
       <map:redirect-to uri="index"/>
     </map:match>
          
    </map:pipeline>
   </map:pipelines>
  
  </map:sitemap>
  
  <!-- end of file -->
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/four/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
  
     <parameter name="persons" type="long" min="2" max="9" default="5" nullable="yes"/>
     <parameter name="deposit" type="double" min="10.0" max="999.99"/>
     <parameter name="email" type="string" max-len="50" matches-regex="^[\d\w][\d\w\-_\.]*@([\d\w\-_]+\.)+\w\w\w?$"/>
     <parameter name="address" type="string" min-len="10" max-len="200" nullable="no"/>
     <parameter name="type" type="string" nullable="no" one-of="|cabrio|sedan|station|racing|"/>
  
     <constraint-set name="car-reservation">
         <validate name="persons"/>
         <validate name="deposit" min="50.0"/>
         <validate name="email"/>
         <validate name="address"/>
         <validate name="type"/>
      </constraint-set>
  
  </root>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/four/form.xml
  
  Index: form.xml
  ===================================================================
  <?xml version="1.0"?>
  <page>
  <head>
  <style type="text/css">
  error {
  	font-style:italic;
  	font-weight:bold;
  	color:red;
  	background-color:#fffbe4;
  	display: block;
  }
  </style>
  </head>
  	<body>
  		<h1>Reserve a car with Cocoon Cars!</h1>
  
  		<p>This last sample combines the techniques demonstrated in the
             previous two samples. Default data is inserted filled into the
             form using a combination of the SimpleFormInstanceTransformer and
             the SimpleFormTransformer. In addition, user input is validated
             with the FormValidatorAction and the submitted data is filled
             in with another SimpleFormTransformer which also selects which 
             error tags shall occurr in the resulting page.</p>
  
  		<h2>Car Reservation</h2>
  		<p>Please fill in the form completely in order to reserve a car.</p>
  		<form name="car" method="post">
              <!-- the transformer can be configured to look for the instance -->
              <!-- data outside the form element. -->
              <form-instance>
                  <persons>4</persons>
                  <deposit>50</deposit>
                  <email>your email</email>
              </form-instance>
  			<table>
  				<tbody>
  					<tr>
  						<td>
              	           The car should seat
  						   <select size="1" name="persons">
  							<option value="" disabled="true">Please select</option>
  						   	<option value="2">2</option>
  						   	<option value="4">4</option>
  						   	<option value="5">5</option>
  						   	<option value="7">7</option>
  						   	<option value="9">9</option>
  						   </select>
  						   Persons.
  						</td>
  						<td>
  							<error name="persons" when-ge="error">*</error>
  						</td>
  					</tr>
  					<tr>
  						<td>
  							The car should by a
  							<select size="1" name="type">
  							<option value="" disabled="true" selected="true">Please select</option>
  							<option value="sedan">Sedan Car</option>
  							<option value="station">Station Wagon</option>
  							<option value="cabrio">Cabrio</option>
  							<option value="racing">Sports Car</option>
  							</select>
  						</td>
  						<td><error name="type" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>
  							I'd like to deposit EUR <input type="text" size="4" name="deposit"/>
  						</td>
  						<td><error name="deposit" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>My email is <input type="text" size="30" name="email"/></td>
  						<td><error name="email" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td>
  							Please bill to
  							<textarea name="address" cols="30" rows="5" />
  						</td>
  						<td><error name="address" when-ge="error">*</error></td>
  					</tr>
  					<tr>
  						<td colspan="2">
  							<error name="*" when-ge="error">An error occurred. Please check your input and the messages below for more information.</error>
  							<error name="persons" when="too-small">The smallest car seats 2.</error>
  							<error name="persons" when="too-large">The largest car seats 9.</error>
  							<error name="deposit" when="too-small">The deposit needs to be at least EUR 50.</error>
  							<error name="deposit" when="is-null">Please specify a deposit.</error>
  							<error name="email" when="is-null">Please fill in an email address.</error>
  							<error name="email" when="no-match">Your email seems incorrect. Please fill in a correct email address.</error>
  							<error name="address" when="is-null">Please fill in a billing address.</error>
  							<error name="address" when="too-small">Your address seems to be incorrect. Please fill in a correct billing address.</error>
  							<error name="type" when="is-null">Please select the type of car you would like to drive.</error>
  							<error name="type" when="no-match">Please select one of the existing type of car.</error>
  						</td>
  					</tr>
  					<tr>
  						<td></td>
  						<td><input type="submit" name="go" value="go!"/></td>
  					</tr>
  				</tbody>
  			</table>
  		</form>
  	</body>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/four/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  
   <map:components>
  
    <!--+
        | In order to use simple form validation, we need to make this action
        | available to the sitemap. Components are inherited, so this could have
        | been done in a parent sitemap. However, to illustrate the usage, we
        | do it here.
        |
        | Note, there are several different validator actions available in
        | Cocoon. They share the same validation code but operate on different
        | values. Here, we're interested in validating request parameters, thus
        | the FormValidatorAction is the right choice.
        |
        | The action is the only component we need to declare - the logicsheet
        | has been added to cocoon.xconf for you already.
        +-->
    <map:actions>
     <map:action name="formval" 
          	   logger="sitemap.action.form-validator" 
          	   src="org.apache.cocoon.acting.FormValidatorAction"/>
    </map:actions>
  
  
  
    <!--+
        | Validation should only occurr when data has been submitted. Therefore
        | a selector is created that will be used to select upon the request method.
        | This is optional if you don't mind to show validation results without
        | user input.
        |
        +-->
    <map:selectors>
      <map:selector name="simple"
                   logger="sitemap.matcher.wildcard"
                   src="org.apache.cocoon.selection.SimpleSelector"/>
    </map:selectors>
  
  
  
    <map:transformers default="xslt">
  
     <!--+ 
         | the SimpleFormTransformer acts upon HTML4 form element tags and 
         | replaces their value attribute or their content in case of the 
         | textarea element with data obtained from an input module attribute 
         | with the same name. In addition, it checks the result of the 
         | FormValidatorAction when it encounters <error/> tags and includes
         | / excludes them depending on the result. 
         |
         +-->
     <map:transformer name="simpleform" 
                      logger="sitemap.transformer.simpleform" 
                      src="org.apache.cocoon.transformation.SimpleFormTransformer">
        <input-module name="request-param"/>
     </map:transformer>
     
     <!--+ 
         | This transformer is used to extract the form instance data from the
         | xml document. See the javadocs of this class for more information on
         | the default configuration and  configuration options.
         |
         | Here, the instance data is nested inside the form element. The
         | transformer can be configured to look for it at other places.
         |
         | The instance data is stored as an attribute with the same name as the 
         | form using an output module. Here we decide to use the RequestAttributeMap
         |  module. This would allows
         | a) to store instances for several forms and 
         | b) to access a particular instance and value using JXPath syntax.
         |
         | Per default, the map key is the name of the form as is the root node 
         | of the new Document.
         |
         +-->
     <map:transformer name="sfinstance" 
                      logger="sitemap.transformer.simpleform-request" 
                      src="org.apache.cocoon.transformation.SimpleFormInstanceExtractionTransformer">
       <output name="request-attr-map"/>
     </map:transformer>
  
     <!--+ 
         | This is the other transformer to read and insert the instance data. 
         | It will be applied first in the pipeline so that the user submitted 
         | data can override the default data. 
         |
         | Only one of the two transformers needs to check for validation errors, 
         | this instance has been instructed to ignore validation results because 
         | looking up the instance data requires to augment the element name with
         | the form name and thus differ from the validation result names.
  	   |
         | The instance extractor places the form instances into a map with the 
         | form name as key. Furthermore, it has been instructed to create a root
         |  element wrapping the instance data with the same name as the form. 
         | Hence we need to included the form's name twice in the element name 
         | used for the lookup.
  	   |
         | In addition, we may want to be able to select from a XSP if the form 
         | data should be replaced with values from the instance or from the 
         | request. Therefore, a different attribute is used to protect element 
         | values.
         |
         +-->
     <map:transformer name="simpleform-instance" 
                      logger="sitemap.transformer.simpleform-instance" 
                      src="org.apache.cocoon.transformation.SimpleFormTransformer">
       <fixed-attribute>this-is-never-used</fixed-attribute>
       <use-form-name-twice>true</use-form-name-twice>
       <ignore-validation>true</ignore-validation>
       <input-module name="jxpath">
         <!--+
             | "jxpath" does not pass the attribute name to the module it
             | obtains the value to act from. Thus an additional attribute
             | name needs to be injected. 
             +-->
         <from-parameter>org.apache.cocoon.components.modules.output.OutputModule</from-parameter>
         <input-module name="request-attr"/>
       </input-module>
      </map:transformer>
  
    </map:transformers>
    
   </map:components>
  
  <!--+
      | This is a standard resource for rendering a XSP page.
      +-->
   <map:resources>
    <map:resource name="static-page">
        <map:transform src="context://samples/common/style/xsl/html/simple-page2html.xsl">
           <map:parameter name="servletPath" value="{request:servletPath}"/>
           <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
           <map:parameter name="contextPath" value="{request:contextPath}"/>
           <map:parameter name="remove" value="{/0}"/>
           <map:parameter name="file" value="{file}.xml"/>
        </map:transform>
        <map:serialize/>
    </map:resource>
   </map:resources>
  
  <!--+
      | These views provide different 'standard' views to the samples.
      |
      +-->
  
   <map:views>
    <map:view name="content" from-label="content">
     <map:serialize type="xml"/>
    </map:view>
  
    <map:view from-label="content" name="pretty-content">
      <map:transform src="context://stylesheets/system/xml2html.xsl"/>
      <map:serialize type="html"/>
    </map:view>
    
    <map:view name="links" from-position="last">
     <map:serialize type="links"/>
    </map:view>
  
   </map:views>
  
  
  <!--+
      | Pipelines
      |
      +-->
  
  
   <map:pipelines>
  
    <map:pipeline>
  
  
     <!-- some redirections -->
     <map:match pattern="">
       <map:redirect-to uri="index"/>
     </map:match>
     
  
  
     <map:match pattern="index">
      <!--+
          | Only validate when data was submitted
          +-->
      <map:select type="simple">
         <map:parameter name="value" value="{request:method}"/>
         <map:when test="POST">
         	  <!--+
         	      | Check the request parameters using the FormValidatorAction 
         	      +-->
         	  <map:act type="formval">
         	    <map:parameter name="descriptor" value="descriptor.xml"/>
         	    <map:parameter name="validate-set" value="car-reservation"/>
         	    <!--+
         	        | this is the success case
         	        |
         	        +-->
         	    <map:generate src="success.xml"/>
         	    <map:transform type="simpleform"/>
      		<map:call resource="static-page">
      		  <map:parameter name="file" value="success"/>
      		</map:call>
         	    <!-- because of the resource above the "success" pipeline ends here. -->
         	  </map:act>
         </map:when>
       </map:select>
       <!--+
           | this branch contains the failed validation.
           | Since the "success" pipeline ends with a resource, the following is only 
           | applied if validation has not been successful.
           |
           +-->
      <map:generate type="file" src="form.xml"/>    
      <!--+
          | extract the instance data
          +-->
      <map:transform type="sfinstance"/>
      <!--+
          | fill in the instance data 
          +-->
      <map:transform type="simpleform-instance"/>
      <!--+
          | fill in the request parameters, and error tags 
          +-->
      <map:transform type="simpleform"/>
      <map:call resource="static-page">
        <map:parameter name="file" value="form"/>
      </map:call>
     </map:match>
  
  
  
     <!-- some redirections -->
     <map:match pattern="*">
       <map:redirect-to uri="index"/>
     </map:match>
          
    </map:pipeline>
   </map:pipelines>
  
  </map:sitemap>
  
  <!-- end of file -->
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/simpleform/four/success.xml
  
  Index: success.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <page>
    <title>Formvalidation and -prefilling</title>
    <content>
  
      <para>
        The entered data successfully passed the validation stage.
      </para>
  
  
      <form name="car" method="post">
         <para>
           A <input type="text" name="type" readonly="true"/> car which seats
  		 <input type="text" name="persons" readonly="true"/> has been reserved for you.
           Please leave the deposit of EUR <input type="text" name="deposit" readonly="true"/>
  		 at the reception. The invoice will be send to <textarea name="address"/> and a
  		 confirmation email will be send to <input type="text" readonly="true" name="email"/>. Thank you.
         </para>
      </form>
  
    </content>
  </page>