Return-Path: Delivered-To: apmail-cocoon-docs-archive@www.apache.org Received: (qmail 45929 invoked from network); 22 Nov 2008 21:15:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Nov 2008 21:15:28 -0000 Received: (qmail 91317 invoked by uid 500); 22 Nov 2008 21:15:37 -0000 Delivered-To: apmail-cocoon-docs-archive@cocoon.apache.org Received: (qmail 91195 invoked by uid 500); 22 Nov 2008 21:15:37 -0000 Mailing-List: contact docs-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: docs@cocoon.apache.org List-Id: Delivered-To: mailing list docs@cocoon.apache.org Received: (qmail 90763 invoked by uid 99); 22 Nov 2008 21:15:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Nov 2008 13:15:36 -0800 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.67] (HELO cocoon.zones.apache.org) (140.211.11.67) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Nov 2008 21:14:20 +0000 Received: from cocoon.zones.apache.org (localhost [127.0.0.1]) by cocoon.zones.apache.org (8.13.8+Sun/8.13.8) with ESMTP id mAML7ZW2007466 for ; Sat, 22 Nov 2008 21:07:35 GMT Message-ID: <8720012.1227388055636.JavaMail.daisy@cocoon.zones.apache.org> Date: Sat, 22 Nov 2008 21:07:35 +0000 (GMT+00:00) From: daisy@cocoon.zones.apache.org To: docs@cocoon.apache.org Subject: [DAISY] Updated: A Simple CForm Example Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org A document has been updated: http://cocoon.zones.apache.org/daisy/documentation/478.html Document ID: 478 Branch: main Language: default Name: A Simple CForm Example (previously A Simple Example) Document Type: Cocoon Document (unchanged) Updated on: 10/15/08 4:09:08 PM Updated by: David Legg A new version has been created, state: publish Parts =3D=3D=3D=3D=3D Content ------- This part has been updated. Mime type: text/xml (unchanged) File name: (unchanged) Size: 16511 bytes (previous version: 15359 bytes) Content diff: (3 equal lines skipped)

A simple CForms example

=20

In this example we will show how to create a simple registration for= m using --- CForms and flowscript. We will follow to following steps:

+++ CForms and flowscript.=C2=A0 We will follow the following steps:

=20
  1. Create a block for this sample
  2. (9 equal lines skipped) =20

    Create a block

    =20 ---

    This has been covered in the tutorial, but it won't hurt to recall t= his Maven --- goal:

    +++

    This is covered in the tutorial "Your first C= ocoon +++ application using Maven 2", but it won't hurt to repeat it here: =20 ---

    mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:cr=
    eate=20
    --- -DarchetypeGroupId=3Dorg.apache.cocoon=20
    --- -DarchetypeArtifactId=3Dcocoon-22-archetype-block=20
    --- -DarchetypeVersion=3D1.0.0-RC2 -DgroupId=3Dcom.mycompany=20
    --- -DartifactId=3Dsimple-sample
    +++

    Choose a suitable parent directory in which to create the following = example +++ directory and then run this Maven command:

    =20 ---

    As of the writing of this page, the Maven archetype p= lugin --- version has to be specified, due to a bug in the current release of it.=

    +++
    mvn archetype:generate -DarchetypeCatalog=3Dhttp://cocoon.apache.o=
    rg
    +++ 
    =20 ---

    Edit the simple-sample/pom.xml file and add the support for= Cocoon --- Forms:

    +++

    Maven will generate some output and then interactively ask you for s= ome +++ information.=C2=A0 You should select item 2 (the cocoon-22-archetype-bl= ock):

    =20 +++
    Choose archetype:
    +++ 1: remote -> cocoon-22-archetype-block-plain (Creates an empty Cocoo=
    n block; useful
    +++ =C2=A0if you want to add another block to a Cocoon application)
    +++ 2: remote -> cocoon-22-archetype-block (Creates a Cocoon block conta=
    ining some small
    +++ =C2=A0samples)
    +++ 3: remote -> cocoon-22-archetype-webapp (Creates a web application c=
    onfigured to
    +++  host Cocoon blocks. Just add the block dependencies)
    +++ Choose a number:  (1/2/3): 2
    +++ 
    +++=20 +++

    When Maven asks for more details of the block to be created answer a= s +++ follows:

    +++=20 +++
     Define value for groupId: : com.mycompany
    +++ Define value for artifactId: : cformexample
    +++ Define value for version:  1.0-SNAPSHOT: : 1.0.0
    +++ Define value for package: : com.mycompany.cformexample
    +++  
    +++=20 +++

    A new directory should appear called 'cformexample'.

    +++=20 +++

    Change into this directory and edit the pom.xml file by add= ing a +++ dependency on Cocoon Forms:

    +++=20
    <dependency>
    --- =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <groupId>org.apache.cocoon</gro=
    upId>
    --- =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <artifactId>cocoon-forms-impl</=
    artifactId>
    --- =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <version>1.0.0-RC1</version>
    +++ =C2=A0 <groupId>org.apache.cocoon</groupId>
    +++ =C2=A0 <artifactId>cocoon-forms-impl</artifactId>
    +++ =C2=A0 <version>1.1.0</version>
        </dependency>
        
    =20 ---

    Move in the simple-sample directory and build the block to = ensure --- the playing field is set appropriately.

    +++

    Build the block to ensure everything is set correctly:

    =20
    mvn install
    =20 ---

    To access resources hold in the fomrs-impla and ajax-impl blocks, th= e Servlet --- Service Framework=C2=A0 has to be instructed to fine them. Hence, open --- src/main/resources/META-INF/cocoon/spring/servlet-service.xml = and add --- the following in the <servlet:context> element:

    +++

    To access resources held in the cocoon-forms-impl and cocoon-ajax-im= pl +++ blocks, the Servlet Service Framework=C2=A0 has to be told how to find = them. Hence, +++ open:

    =20 ---
    <servlet:connections>
    ---   <entry key=3D"ajax" value-ref=3D"org.apache.cocoon.ajax.impl.servl=
    et"/>
    --- =C2=A0 <entry key=3D"forms" value-ref=3D"org.apache.cocoon.forms.imp=
    l.servlet"/>
    --- </servlet:connections>
    +++

    src/main/resources/META-INF/cocoon/spring/block-servlet-service.= xml +++

    =20 +++

    Find the following line:

    +++=20 +++
    <servlet:context mount-path=3D"/cformexample" context-path=3D"b=
    lockcontext:/cformexample/"/>
    +++ 
    +++=20 +++

    and change it to look like this:

    +++=20 +++
    <servlet:context mount-path=3D"/cformexample" context-path=3D"b=
    lockcontext:/cformexample/">
    +++   <servlet:connections>
    +++     <entry key=3D"ajax" value-ref=3D"org.apache.cocoon.ajax.impl.ser=
    vlet"/>
    +++     <entry key=3D"forms" value-ref=3D"org.apache.cocoon.forms.impl.s=
    ervlet"/>
    +++   </servlet:connections>
    +++ </servlet:context>
    +++ 
    +++=20

    Create a form definition file

    =20

    Below the form definition file is displayed, (189 equal lines skipped) =20

    Add some pipelines to the sitemap

    =20 ---

    The sitemap.xmap has to be modified as well:

    +++

    The sitemap.xmap has to be modified (located in: src\main\resources\= COB-INF): +++

    =20 ---

    First, an i18n dictionary has to be definied:

    +++

    First, an i18n dictionary has to be defined:

    =20
    =C2=A0 <map:components>
        =C2=A0=C2=A0=C2=A0 <map:transformers default=3D"xslt">
    (39 equal lines skipped)
                <map:generate type=3D"jx" src=3D"resource/internal/registrat=
    ion_success.jx"/>
                <map:serialize/>
              </map:match>
    ---     </map:pipeline
    +++ </map:pipeline> =20

    Note the following things:

    =20 (2 equal lines skipped) forms catalogue does not have to be the default one, but here it is the= only one and thus the default.
  3. In the map:flow tag our flowscript file is NOT declared, s= ince --- Cocoon loads automatically what's in the flow directory.
  4. +++ Cocoon automatically loads whatever is in the flow directory.<= /li>
  5. Then we have the pipelines:
    • The first two are for managing the flowscript: when someone hits th= e (9 equal lines skipped) javascript libraries, CSS files and images.
    • Resources (XSL files, CSS, images, etc.) defined in the forms-impl = and ajax-impl blocks are provided to this block by the Servlet Service Fram= ework --- (look at the paramters given to forms-samples-styling.xsl). +++ (look at the parameters given to forms-samples-styling.xsl).
    =20 (57 equal lines skipped) =20

    Direct your browser to:

    =20 ---
    http://localhost:8888/simple-sample/registration
    +++ 
    http://localhost:8888/cformexample/registration
        
    =20

    Try entering incorrect data and see what it does.

    (4 equal lines skipped) a simple form (though notice you didn't have to write any Java for all = of this, nor to restart Cocoon), but adding more complexity to the form is now s= imply a matter of adding more widgets, custom validation logic, event handlers,= etc. To --- have a feel for the power of CForms, take a look at the examples includ= ed +++ get a feel for the power of CForms, take a look at the examples include= d included in the Forms block.

    =20 (1 equal lines skipped)