Making the Connection—Binding
The
remaining detail is how to associate model item properties with
particular instance data nodes. The answer is binding, but
it’s worth being extra clear with terminology: a
bind has two ends, one side in the XForms Model, and the other side
at a form control. On the bind element within the
XForms Model, the nodeset attribute holds the
Model Binding Expression. On the other end, in the user interface, is
the UI Binding Expression. This end may be bound two ways, using
either IDREFs or XPath.
With IDREFs
The recommended way to perform binding
is to put an
id attribute on each
bind element, and refer back to this with a
bind attribute on each form control:
<!-- in the XForms Model --> <xforms:bind nodeset="email" id="mybind" required="true()"/> ... <!-- later in the document --> <xforms:input bind="mybind"...>
This approach is distinguished by the use of the
bind attribute on form controls. The main
advantage of this approach is that it maintains separation between
the model and the view. If the structure of the instance data were to
change, only the attributes on the bind elements
would need to be updated. In large organizations, form authoring
often involves separate teams: a graphic design team to lay out the
form, and a systems team to handle the data integration. In such
scenarios, IDREF binding provides a perfect interface between content
and presentation.
With XPath
Another way to bind is with XPath expressions on the form controls:
<!-- in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access