Dynamic sections in XForms

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic sections in XForms

rovsh
Hello,

In my form, I have sections with fields which are generated depending on source data. For instance, in database we have a set of records (a pair of key and value):
Records:
key: 1, value: One
key: 2, value: Two.

From this data I would like to generate 2 sections containing 3 fields:
Section 1
1. Checkbox having as a value 1, the key from Record 1 and label: One from Record 1.
2. Input field 1. (needs to be bind to model)
3. Input field 2. (needs to be bind to model)

Section 2
1. Checkbox having as a value 2, the key from Record 2 and label: Two from Record 2.
2. Input field 1. (needs to be bind to model)
3. Input field 2. (needs to be bind to model)

If user checks any of the checkboxes, corresponding values should be saved in model, and when form is edited, while generating the sections, corresponding data should be loaded from model.

I know that generating sections with 3 controls can be done using <xforms:repeat ref="our instance with records">. However, I am not sure how the rest of requirements (binding, saving/loading data) can be accomplished.
Can you please give some advices and hints? Maybe somebody already did something similar.
Please let me know if further clarification is needed.

Thanks in advance.

-Rovsh
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic sections in XForms

Alessandro  Vernet
Administrator
Hi Rovsh,

You could use just XForms for something like this, but in general people find it easier to use another language to generate the XForms based on the non-XForms definition of the form (in your case, information stored in your database). XSLT is is often used for this. So one could do:

1. Retrieve the data describing the form from the database and encode that in XML.
2. Using XSLT, produce XForms based on the document generated in 1.
3. Orbeon Forms XForms engine "runs" the output of 2.

And you could use a pipeline (XPL) to put together those steps 1 -> 2 -> 3.

Alternatively, you could write Java code that generates the XForms, this in a separate web app, and use separate deployment (see link below) to feed the XForms you generate in your app to the Orbeon Forms web app.

http://wiki.orbeon.com/forms/doc/developer-guide/xforms-with-java-applications

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet