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.
contactsList.addAll(contactsData);
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!
[EMAIL PROTECTED] 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
formMap.putAll(customer);
form.showForm("viewform");
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
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]