cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Updated: A Simple Example
Date Fri, 14 Mar 2008 10:37:25 GMT
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:37:20 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: 15363 bytes (previous version: 13839 bytes)
Content diff:
(60 equal lines skipped)
    
    <p>Below the form definition file is displayed,
    <tt>registration_definition.xml</tt> (to be put under
--- <tt>src/main/resources/COB-INF/resource/external</tt> directory). This lists
all
+++ <tt>src/main/resources/COB-INF/resource/internal</tt> directory). This lists
all
    the widgets in the form, together with their configuration information:</p>
    
    <pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
(73 equal lines skipped)
    
    <p>Here is the template for our registration form example,
    <tt>registration_template.xml</tt> (to be put under
--- <tt>src/main/resources/COB-INF/resource/external</tt> directory):</p>
+++ <tt>src/main/resources/COB-INF/resource/internal</tt> directory):</p>
    
    <pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;html xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
(78 equal lines skipped)
    <pre>cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
    
    function registration() {
---     var form = new Form("registration_definition.xml");
+++     var form = new Form("cocoon://resource/internal/registration_definition.xml");
    
        form.showForm("registration-display-pipeline");
    
        var viewData = { "username" : form.getChild("name").getValue() }
        cocoon.sendPage("registration-success-pipeline", viewData);
--- }</pre>
+++ }
+++ </pre>
    
    <p>The flowscript works as follows:</p>
    
(12 equal lines skipped)
    
    <h1>Add some pipelines to the sitemap</h1>
    
--- <p>Here is the sitemap we need, <tt>sitemap.xmap</tt>:</p>
+++ <p>The sitemap.xmap has to be modified as well:</p>
    
--- <pre>&lt;?xml version="1.0"?&gt;
--- &lt;map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"&gt;
+++ <p>First, an i18n dictionary has to be definied:</p>
    
---   &lt;map:components&gt;
---     &lt;map:transformers default="xslt"&gt;
---       &lt;map:transformer name="i18n"
---         src="org.apache.cocoon.transformation.I18nTransformer"&gt;
---         &lt;catalogues default="forms"&gt;
---           &lt;catalogue id="forms" name="messages"
---             location="resource://org/apache/cocoon/forms/system/i18n"/&gt;
---         &lt;/catalogues&gt;
---         &lt;cache-at-startup&gt;true&lt;/cache-at-startup&gt;
---       &lt;/map:transformer&gt;
---     &lt;/map:transformers&gt;
---   &lt;/map:components&gt;
+++ <pre>  &lt;map:components&gt;
+++     &lt;map:transformers default="xslt"&gt;
+++       &lt;map:transformer name="i18n"
+++         src="org.apache.cocoon.transformation.I18nTransformer"&gt;
+++         &lt;catalogues default="forms"&gt;
+++           &lt;catalogue id="forms" name="messages"
+++             location="resource://org/apache/cocoon/forms/system/i18n"/&gt;
+++         &lt;/catalogues&gt;
+++         &lt;cache-at-startup&gt;true&lt;/cache-at-startup&gt;
+++       &lt;/map:transformer&gt;
+++     &lt;/map:transformers&gt;
+++   &lt;/map:components&gt;</pre>
    
---   &lt;map:views&gt;
---   &lt;/map:views&gt;
+++ <p>Then some pipelines to process the form:</p>
    
---   &lt;map:resources&gt;
---   &lt;/map:resources&gt;
+++ <pre>    &lt;!-- 
+++       Registration form pipeline 
+++     --&gt;
+++     &lt;map:pipeline&gt;
+++       
+++       &lt;map:match pattern="registration"&gt;
+++         &lt;map:call function="registration"/&gt;
+++       &lt;/map:match&gt;
    
---   &lt;map:flow language="javascript"&gt;
---     &lt;map:script src="registration.js"/&gt;
---   &lt;/map:flow&gt;
+++       &lt;map:match pattern="*.continue"&gt;
+++         &lt;map:call continuation="{1}"/&gt;
+++       &lt;/map:match&gt;
    
---   &lt;map:pipelines&gt;
+++       &lt;map:match pattern="registration-display-pipeline"&gt;
+++         &lt;map:generate type="jx" src="resource/internal/registration_template.xml"/&gt;
+++         &lt;map:transform type="i18n"&gt;
+++           &lt;map:parameter name="locale" value="en"/&gt;
+++         &lt;/map:transform&gt;
+++         &lt;map:transform src="resource/internal/forms-samples-styling.xsl"&gt;
+++           &lt;map:parameter name="forms-resources" value="{servlet:forms:/resource/external/forms}"/&gt;
+++           &lt;map:parameter name="dojo-resources" value="{servlet:ajax:/resource/external/dojo}"/&gt;
+++         &lt;/map:transform&gt;
+++         &lt;map:serialize/&gt;
+++       &lt;/map:match&gt;
+++       
+++       &lt;map:match pattern="registration-success-pipeline"&gt;
+++         &lt;map:generate type="jx" src="resource/internal/registration_success.jx"/&gt;
+++         &lt;map:serialize/&gt;
+++       &lt;/map:match&gt;
+++     &lt;/map:pipeline</pre>
    
---    &lt;map:pipeline&gt;
---      &lt;map:match pattern="registration"&gt;
---        &lt;map:call function="registration"/&gt;
---      &lt;/map:match&gt;
--- 
---      &lt;map:match pattern="*.continue"&gt;
---        &lt;map:call continuation="{1}"/&gt;
---      &lt;/map:match&gt;
--- 
---      &lt;map:match pattern="registration-display-pipeline"&gt;
---        &lt;map:generate type="jx" src="registration_template.xml"/&gt;
---        &lt;map:transform type="i18n"&gt;
---          &lt;map:parameter name="locale" value="en-US"/&gt;
---        &lt;/map:transform&gt;
---        &lt;map:transform src="forms-samples-styling.xsl"/&gt;
---        &lt;map:serialize/&gt;
---      &lt;/map:match&gt;
--- 
---      &lt;map:match pattern="registration-success-pipeline"&gt;
---        &lt;map:generate type="jx" src="registration_success.jx"/&gt;
---        &lt;map:serialize/&gt;
---      &lt;/map:match&gt;
--- 
---      &lt;map:match pattern="resources/*/**"&gt;
---        &lt;map:read src="resource://org/apache/cocoon/{1}/resources/{2}"/&gt;
---      &lt;/map:match&gt;
--- 
---    &lt;/map:pipeline&gt;
--- 
---  &lt;/map:pipelines&gt;
--- 
--- &lt;/map:sitemap&gt;
--- </pre>
--- 
    <p>Note the following things:</p>
    
    <ul>
    <li>The i18n transformer is configured so it knows about the forms messages. The
    forms catalogue does not have to be the default one, but here it is the only one
    and thus the default.</li>
--- <li>In the <tt>map:flow</tt> tag our flowscript file is declared.</li>
+++ <li>In the <tt>map:flow</tt> tag our flowscript file is NOT declared,
since
+++ Cocoon loads automatically what's in the <tt>flow</tt> directory.</li>
    <li>Then we have the pipelines:</li>
    <ul>
    <li>The first two are for managing the flowscript: when someone hits the
(7 equal lines skipped)
    below.</li>
    <li>The last one is for making default CForms resources available, such as
    javascript libraries, CSS files and images.</li>
+++ <li>Resources (XSL files, CSS, images, etc.) defined in the forms-impl and
+++ ajax-impl blocks are provided to this block by the Servlet Service Framework
+++ (look at the paramters given to <tt>forms-samples-styling.xsl</tt>).</li>
    </ul>
    
    </ul>
    
    <p>As promised, here is the content of the <tt>registration_success.jx</tt>
--- file:</p>
+++ file (add it to
+++ <tt><tt>src/main/resources/COB-INF/resource/internal)</tt></tt>:</p>
    
    <pre>&lt;?xml version="1.0"?&gt;
    &lt;html&gt;
(6 equal lines skipped)
    &lt;/html&gt;
    </pre>
    
--- <p>One last thing you need to do is to copy the following file, which you find
--- in the Cocoon download, to your test directory:</p>
+++ <p>One last thing you need to do is to add an XSLT file with this content (add
+++ it to <tt><tt>src/main/resources/COB-INF/resource/internal</tt></tt>
and name it
+++ <tt>forms-samples-styling.xsl</tt>):</p>
    
--- <pre>src/blocks/forms/samples/resources/forms-samples-styling.xsl</pre>
+++ <pre>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
+++   &lt;xsl:include href="servlet:forms:/resource/internal/xsl/forms-page-styling.xsl"/&gt;
+++   &lt;xsl:include href="servlet:forms:/resource/internal/xsl/forms-field-styling.xsl"/&gt;
+++   
+++   &lt;!-- Location of the resources directories, where JS libs and icons are stored
--&gt;
+++   &lt;xsl:param name="dojo-resources"/&gt;
+++   &lt;xsl:param name="forms-resources"/&gt;
    
+++   &lt;xsl:template match="head"&gt;
+++     &lt;head&gt;
+++       &lt;xsl:apply-templates select="." mode="forms-page"/&gt;
+++       &lt;xsl:apply-templates select="." mode="forms-field"/&gt;
+++       &lt;xsl:apply-templates/&gt;
+++     &lt;/head&gt;
+++   &lt;/xsl:template&gt;
+++ 
+++   &lt;xsl:template match="body"&gt;
+++     &lt;body&gt;
+++       &lt;xsl:apply-templates select="." mode="forms-page"/&gt;
+++       &lt;xsl:apply-templates select="." mode="forms-field"/&gt;
+++       &lt;xsl:apply-templates/&gt;
+++     &lt;/body&gt;
+++   &lt;/xsl:template&gt;
+++ 
+++ &lt;/xsl:stylesheet&gt;
+++ 
+++ </pre>
+++ 
    <h1>Try it out</h1>
    
    <p>If you have created all the files mentioned above, you can now try out this
--- sample by browsing to:</p>
+++ sample.</p>
    
--- <pre>http://localhost:8888/myformtest/registration
+++ <p>Build the thing and fire up jetty:</p>
+++ 
+++ <pre>mvn jetty:run
    </pre>
    
+++ <p>Direct your browser to:</p>
+++ 
+++ <pre>http://localhost:8888/simple-sample/registration
+++ </pre>
+++ 
    <p>Try entering incorrect data and see what it does.</p>
    
    <h1>Next steps</h1>
(10 equal lines skipped)


Mime
View raw message