A document has been updated: http://cocoon.zones.apache.org/daisy/documentation/478.html
Document ID: 478 Branch: main Language: default Name: A Simple Example (unchanged) Document Type: Cocoon Document (unchanged) Updated on: 3/14/08 10:06:29 AM Updated by: Luca Morandini A new version has been created, state: draft Parts ===== Content ------- This part has been updated. Mime type: text/xml (unchanged) File name: (unchanged) Size: 13839 bytes (previous version: 12210 bytes) Content diff: (6 equal lines skipped) CForms and flowscript. We will follow to following steps:</p> <ol> +++ <li>Create a block for this sample</li> <li>Create a form definition file</li> <li>Create a template file</li> <li>Write a bit of flowscript</li> <li>Add some pipelines to the sitemap</li> </ol> --- <p>You can try this sample out on a default Cocoon install. In the webapp --- directory (build/webapp), create a new subdirectory, for example called --- <tt>myformtest</tt>. In there, create the files as outlined in this sample.</p> --- <p>Here is a screenshot of the form we're going to create:</p> <p align="center"><img src="daisy:350"/></p> +++ <h1>Create a block</h1> +++ +++ <p>This has been covered in the tutorial, but it won't hurt to recall this Maven +++ goal:</p> +++ +++ <pre>mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create +++ -DarchetypeGroupId=org.apache.cocoon +++ -DarchetypeArtifactId=cocoon-22-archetype-block +++ -DarchetypeVersion=1.0.0-RC2 -DgroupId=com.mycompany +++ -DartifactId=simple-sample</pre> +++ +++ <p class="note">As of the writing of this page, the Maven archetype plugin +++ version has to be specified,due to a bug in the current release of it.</p> +++ +++ <p>Edit the <tt>simple-sample/pom.xml</tt> file and add the support for Cocoon +++ Forms:</p> +++ +++ <pre><dependency> +++ <groupId>org.apache.cocoon</groupId> +++ <artifactId>cocoon-forms-impl</artifactId> +++ <version>1.0.0-RC1</version> +++ </dependency> +++ </pre> +++ +++ <p>Move in the <tt>simple-sample</tt> directory and build the block to ensure +++ the playing field is set appropriately.</p> +++ +++ <pre>mvn install</pre> +++ +++ <p>To access resources hold in the fomrs-impla and ajax-impl blocks, the Servlet +++ Service Framework has to be instructed to fine them. Hence, open +++ <tt>src/main/resources/META-INF/cocoon/spring/servlet-service.xml</tt> and add +++ the following in the<tt> servlet-context</tt> element:</p> +++ +++ <pre><servlet:connections> +++ <entry key="ajax" value-ref="org.apache.cocoon.ajax.impl.servlet"/> +++ <entry key="forms" value-ref="org.apache.cocoon.forms.impl.servlet"/> +++ </servlet:connections></pre> +++ <h1>Create a form definition file</h1> <p>Below the form definition file is displayed, --- <tt>registration_definition.xml</tt>. This lists all the widgets in the form, --- together with their configuration information.</p> +++ <tt>registration_definition.xml</tt> (to be put under +++ <tt>src/main/resources/COB-INF/resource/external</tt> directory). This lists all +++ the widgets in the form, together with their configuration information:</p> --- <pre><fd:form +++ <pre><?xml version="1.0" encoding="UTF-8"?> +++ <fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"> <fd:widgets> (68 equal lines skipped) <h1>Create a template file</h1> <p>Here is the template for our registration form example, --- <tt>registration_template.xml</tt>:</p> +++ <tt>registration_template.xml</tt> (to be put under +++ <tt>src/main/resources/COB-INF/resource/external</tt> directory):</p> --- <pre><html xmlns:ft="http://apache.org/cocoon/forms/1.0#template" +++ <pre><?xml version="1.0" encoding="UTF-8"?> +++ <html xmlns:ft="http://apache.org/cocoon/forms/1.0#template" xmlns:fi="http://apache.org/cocoon/forms/1.0#instance" xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"> (4 equal lines skipped) </head> <body> <h1>Registration</h1> --- <ft:form-template action="#{$continuation/id}.continue" method="POST"> +++ <ft:form-template action="#{$cocoon/continuation/id}.continue" method="POST"> <ft:widget-label id="name"/> <ft:widget id="name"/> <br/> (58 equal lines skipped) is based on the concept of continuations. If you don't know yet about continuations and flowscript, <a href="daisy:517">learn about it here</a>.</p> --- <p>Here's the flowscript for our example, <tt>registration.js</tt>:</p> +++ <p>Here's the flowscript for our example, <tt>registration.js</tt> (put it under +++ <tt>src/main/resources/COB-INF/flow</tt>):</p> <pre>cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js"); (154 equal lines skipped)