Avoka Blog: Adobe LiveCycle

January 12, 2009

Populating a drop-down using XML and Dynamic Binding

Filed under: Designing Forms, LiveCycle Forms — htreisman @ 8:45 pm

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.

Note:

  • 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

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.

Form Design

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

data_connection

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:

xml

Step 5:Turn on Dynamic Binding

This is available from the drop-down menu of the Object palette in Designer.

Dynamic Properties

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:

drop_down_bindings

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.

preview_data

Click on the Preview tab. You should see something like this:

final_form

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.

Finally

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 info@avoka.com

Advertisements

7 Comments »

  1. Hi htreisman,

    Thank you for this article.

    I really find it very useful.

    I wanted to ask two:

    Is it possible to know the software used to develop the xml schema, which screen shot is shown above?

    I was wondering the best way to populate more than two fields using xml schema. Say I have a set of books that I want to have populated in a xfa form. And I would like when a particular book title is selected in drop-down list A then a second drop-down list B gets populated with the author name and then a third drop-down list C gets populated with the year of publication.

    Thank you in advance for your help.

    Comment by E. Loralon — February 21, 2009 @ 5:28 am

  2. Thanks a lot Howard,

    I will be looking forward to your next post.

    Have great day.

    Comment by E. Loralon — February 24, 2009 @ 3:37 am

  3. Hi Howard,

    I am new to creating schemas, can you send the schema that you used for this example? It’s a great article and will definitely help with what I am looking to do. Thanks very much!

    Comment by Elaine Schmitz — February 27, 2009 @ 3:50 am

  4. Hi Elaine
    The schema is embedded inside the PDF. Just open it in Reader, click the paper-clip icon, and you’ll find both the XML schema and a sample XML data file.
    Howard

    Comment by htreisman — March 1, 2009 @ 8:20 am

  5. Hi,

    That was great! I am using excel and/or access to create my shemas, and its driving me slightly insane…I would like to be able to select a suppliers name, and have all their contact details automatically populate with in the form…any ideas??

    Comment by Jess B — April 3, 2009 @ 3:22 pm

    • Hi Jessica
      I’m not quite sure what you mean about excel/.access, can you elaborate.
      Also, are you talking about a handful of fairly static suppliers, or a large number in some sort of database – the approaches do vary?
      Shoot me an email to htreisman-at-avoka.com and we can discuss…
      Howard

      Comment by htreisman — April 3, 2009 @ 10:20 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: