1 / 9

Apache Cocoon

Apache Cocoon. Part II 3/6/06 Kevin Davis. Learning Objectives. Understand how CForms work Understand how XSPs work Make a basic CForm that can pass information to an XSP. Cocoon Forms vs HTML Forms. Cocoon forms – use XML to make reusable form objects with easy validation

badu
Download Presentation

Apache Cocoon

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Apache Cocoon Part II 3/6/06 Kevin Davis

  2. Learning Objectives • Understand how CForms work • Understand how XSPs work • Make a basic CForm that can pass information to an XSP

  3. Cocoon Forms vs HTML Forms • Cocoon forms – use XML to make reusable form objects with easy validation • HTML forms – must write all forms individually and use Javascript or other languages for some validation • See working samples at http://blaze.terry.uga.edu:8080/cocoon/samples/blocks/forms/

  4. Widgets • XML entities in the definition file that give a form field its name and validation information <fd:field id="email" required="true"> <fd:label>Email address:</fd:label> <fd:datatype base="string"/> <fd:validation> <fd:email/> </fd:validation> </fd:field> • Called in the template file along with HTML code for formatting <br/> <ft:widget-label id="email"/> <ft:widget id="email"/> • Have built-in responses to validation issues, including help tooltips and redisplaying the form if something wasn’t correct

  5. Flow • A Javascript file and the sitemap control the order in which pages are called function registration() { var form = new Form("registration_definition.xml"); form.showForm("registration-display-pipeline"); var viewData = { "username" : form.getChild("name").getValue() } cocoon.sendPage("registration-success-pipeline", viewData); }

  6. Flow Continued <map:flow language="javascript"> <map:script src="registration.js"/> </map:flow> … <map:pipeline> <map:match pattern="registration"> <map:call function="registration"/> </map:match> … <map:match pattern="registration-display-pipeline"> <map:generate type="jx" src="registration_template.xml"/> <map:transform type="i18n"> <map:parameter name="locale" value="en-US"/> </map:transform> <map:transform src="forms-samples-styling.xsl"/> <map:serialize/> </map:match> … <map:match pattern="registration-success-pipeline"> <map:generate type="jx" src="registration_success.jx"/> <map:serialize/> </map:match>

  7. XSPs • Much like servlets, XSPs can request data from a submitted form and insert it into a database, or call and display data from a database • XML tags and Java code can be used • Connection to a database occurs in one Cocoon configuration file, XSPs just need to call the name of the database

  8. XSPs Continued <esql:connection> <esql:pool>otc</esql:pool> <esql:execute-query> <esql:query> INSERT into otc_users (name,email,password,age,spam) values ('<xsp:expr>esc_name</xsp:expr>','<xsp- request:get-parameter name="email"/>','<xsp- request:get-parameter name="password"/>','<xsp- request:get-parameter name="age"/>','<xsp-request:get- parameter name="spam"/>') </esql:query> </esql:execute-query> </esql:connection> … <xsp:logic> [java code] </xsp:logic>

  9. Exercise • Follow the guide located at http://cocoon.apache.org/2.1/userdocs/basics/sample.html - create your own template and definition files with at least one unique widget • Compare this to the working example located at http://blaze.terry.uga.edu:8080/cocoon/cforms/registration • Look at the files sitemap-modified.xmap and test.xsp in the opt/tomcat5/webapps/cocoon/cforms directory to see how a CForm could use an XSP to insert data into a database

More Related