In one of our previous blogs, we mentioned several techniques for populating a drop-down list with data. In this posting, we’re going to use a technique called “Dynamic Binding”. We’re going to use an XML file to populate the drop-down, as well as for populating a repeating lists of questions.
The form we’re going to develop is a general purpose survey form, where both the list of questions, and the answers allowed, are pre-populated with XML. Since Designer only supports a single XML file, we’re going to store the drop-down values, the questions, and the answers that the end-user selects, all in the same XML file.
The Sample PDF is here: dynamic_survey_with_embedded_data. Try it out before you start the exercise, so you can see what we’ll end up achieving.
- You can just open this file in Reader to try it out
- You can open it in Designer to see how it works
- The PDF has two attachments, the XML schema and a sample XML file. Click on the paper-clip icon to get at these.
It also contains the sample XML and schema files as embedded attachments.
Step 1: create the schema
Note that “Question” and “ResponseItem” are repeating, with a cardinality of 1..*. “Questions” will be used to populate the list of questions dynamically. “ResponseItems” will be used to populate the drop-down list containing the user’s responses.
Step 2: Create a simple form
You must save it as a Dynamic PDF form, because it’s going to grow based on the data we put into it. Also, because we’re going to grow the number of questions based on the data in the XML file, we need to use a Flowed rather than Positioned layout.
Note that the table has only one row (set to “repeating” on the binding tab), and a DropDown list with no values specified.
Step 3: Add the schema to the form
Add the schema to the form by defining a new data connection. Embedding the schema is optional, but useful if you’re ever going to use this form within a LiveCycle process.
Step 4: Create the XML file
Make sure it conforms to your schema. Here’s a snippet:
Step 5:Turn on Dynamic Binding
This is available from the drop-down menu of the Object palette in Designer.
Step 6: Bind the schema elements to the form objects
Use the Binding sub-tab of the Object palette.
- Bind Row1 to the Question[*] repeating group – this will ensure that for every row of Question data in the XML, we’ll get a new Row1 in the form.
- Bind the Question and Answer fields to the sub-elements of the repeating group. Note that you use relative binding, because the repeating element is already bound to Row1.
Step 7: Dynamic Binding
Bind the drop-down’s values and labels to the elements defined in the schema. Click on the green “Specify Item Values” link, and in the Dynamic properties dialog, enter the repeating element, and the sub-items containing the text (the values displayed) and value (the values stored in the data). This is summarized in the screenshot below:
If you don’t see the green link, revisit Step 5.
Step 8: Preview the form
In Designer, set the “Data File” to point to your sample xml file.
Click on the Preview tab. You should see something like this:
Try changing the data in the sample XML file (for example, adding “No opinion” to the drop-down data, or a new question), and then preview again. You should see the new question and drop-down items appear.
You can embed the XML data into the form manually using Acrobat or automate it on the server via LiveCycle Forms or Process Management. Using a LiveCycle orchestration, you could of course generate the XML using a database query or some other source.
If you’d like more information on how to do this, please contact firstname.lastname@example.org