You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Bruno Dumon <br...@outerthought.org> on 2004/06/29 18:44:16 UTC
Re: Forms: building data-driven form definition files, is it
possible?
On Tue, 2004-06-29 at 17:07, Enrico Migliore wrote:
> Hi guys,
>
> I'm developing a web application where the user retrieves data from a DB,
> for update. I would like to use Cocoon Forms for submitting the data.
> The problem I got is that each query is different from the other, and I
> can't build a universal form definition file. The problem here is that
> I don't know in advance the size of the recordset coming out from the DB.
"size of the recordset": I assume then that each resulting record would
describe another field? Otherwise a repeater is what you need.
Only dynamically generate your forms if it's really necessary.
>
> I would like to build the form definition file based upon the retrieved
> data,
> and not load a static file.
> The major problem seems to be the following:
>
> FormInstance form = new FormInstance("forms/form1.xml");
>
> That dictates that the form definition file must be static and can't
> be an XML stream.
>
> Has someone solved this problem?
Here's a snippet of code that should do it (in Java):
PipelineUtil pipelineUtil = new PipelineUtil();
FormManager formManager = null;
try {
LifecycleHelper.setupComponent(pipelineUtil, null, context, serviceManager, null, null, false);
Map viewData = new HashMap();
// optional: put anything in viewData that you might need in the view
org.w3c.dom.Document formDocument = pipelineUtil.processToDOM("MyPipe", viewData);
formManager = (FormManager)serviceManager.lookup(FormManager.ROLE);
Form form = formManager.createForm(formDocument.getDocumentElement());
return form;
} finally {
LifecycleHelper.dispose(pipelineUtil);
if (formManager != null)
serviceManager.release(formManager);
}
An alternative approach is to simply use a "cocoon:/..." URL as argument
to the FormInstance class, but that will be somewhat slower since it
will need an additional parse in between, and I think the FormManager
will also cache the FormDefinition even if it's uncacheable.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org