Return-Path:
In this example we will show how to create a simple registration for=
m using
--- CForms and flowscript. We will follow to following steps:A simple CForms example
=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:
=20mvn 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
Below the form definition file is displayed, (189 equal lines skipped) =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.Direct your browser to:
=20 ---http://localhost:8888/simple-sample/registration +++http://localhost:8888/cformexample/registration=20Try 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