cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hohls" <>
Subject Re: CForms / Flow + database actions?
Date Mon, 10 Oct 2005 12:59:54 GMT
" just use the same names for your form fields 
and the database columns!"
Cool!   Have just been reading through Andrews' Get
Together presentation on "Simplifying Cocoon" and I
am sure this aspect fits right in with what he is calling
for... many (most?) of the pieces of the "Simple Cocoon"
are there - by 2.2 what he is suggesting should be do-able?

>>> 2005/10/10 02:46 PM >>>
Derek Hohls wrote:

>Yet again, the wizards add something new to the hat for us to pull out!
>Quick question - will this approach allow for mapping of parent->child
>relationships - where both parent and child (and maybe "grand children"?)
>are updated on the same form?!

Yup, it is possible. Add to this to the previous example:

// Get the "contact" repeater as a list of maps (one per row)
var contactsList = formMap.get("contacts");

var contactsData = jdbi.query("select * from concacts where customer_id 
= :id",
{ id: cocoon.request.getParameter("id"));

// Fill the repeater with all contacts for this customer.

Saving requires a bit more code, as you have to iterate over the 
contactsList element and store them one by one. Also, you have to track 
added and deleted rows to know whether to delete, insert or update. I'm 
currently writing some helper code for this...

>PS The fragment does not show this, but I assume there is some simple
>way to map between database fields and form fields when filling out
>the form? Or is this already catered for in the CForms aspect?

Oh no, it's even simpler: just use the same names for your form fields 
and the database colums!

>>>> 2005/10/10 11:50 AM 

>Yup. This is something I'm working on for my current project and which 
>should land this week in the SVN.
>Basically, JDBI allows to access JDBC using List and Map rather than 
>ResultSet, and I added List and Map implementations that wrap a CForms 
>repeater and container, respectively.
>This allows to write things like:
>var form = new Form("myform.xml");
>// Get a Map view on the form
>var formMap = form.asMap();
>// Load a Map representing a customer from the database
>var customer = jdbi.query("select * from customer where id = :id", { id: 
>cocoon.request.getParameter("id") });
>// Fill the form
>if (form.isValid) {
>// Update customer
>jdbi.update("update customer set name = :name, email = :email where 
>id = :id", formMap);
>Et voilĂ : for simple CRUD needs, direct mapping from database table to 
>form without complex O/R mapping tools.

Sylvain Wallez Anyware Technologies 
Apache Software Foundation Member Research & Technology Director

To unsubscribe, e-mail: 
For additional commands, e-mail: 

This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.
CSIR E-mail Legal Notice 
CSIR Copyright, Terms and Conditions 
For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message