5.5 Making the ConnectionBinding

5.5 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.

5.5.1 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"  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.

5.5.2 With XPath

Another way to bind is with XPath expressions on the form controls:

<!-- in the XForms Model --> <xforms:bind nodeset="email"  required="true(  )"/> ... <!-- later in the document --> <xforms:input ref="email"...>

This approach is distinguished by the use of ref attributes on form controls. Many view this approach as simpler, since it cuts out one level of indirection. It is also more fragile, however, since the XPath expressions to locate nodes appear in two places. If the structure of the instance data were to change, both the attributes on the bind element and the ref attributes on the form controls would need to change.

5.5.3 Multiple Models

It's common to have multiple forms in the same document, and thus have multiple XForms Models. The document markup for this is straightforward:

<!-- in the XForms Model 1 --> <xform:model >   <xforms:bind nodeset="email" type="my:email"/>   ... </xforms:model> <xforms:model >   <xforms:bind nodeset="search" type="my:query"/>   ... </xforms:model> <!-- later in the document --> <xforms:input ref="email" model="m1"...> <xforms:input ref="search" model="m2"...>

When using IDREF binding, this causes no additional problems, since the ID the form control points to is necessarily unique in the document. When using XPath binding, however, additional information is needed. In which model do you find purchaseOrder/items/item[2]? Because of this dilemma, in any document with two or more XForms Models, every XPath-style binding needs an additional attribute, model, to indicate which model is being bound to. By design, each XForms Model is a self-contained unit, and options for cross-model communication are limited.

5.5.4 Multiple Instances

A common scenario is that a form needs some extra data, perhaps for a calculation. In HTML forms, hidden fields could be used for this. But in XForms, the initial form data is XML, which is already widely deployed. Often, it's not possible to modify existing DTDs and XML Schemas to add new forms-specific elements and attributes to legacy XML. In these cases, it is possible to set aside additional XForms Instances as temporary storage.

On the markup side, this, too, is straightforward using multiple instance elements:

<!-- in the XForms Model --> <xforms:model>   <xforms:instance >     <my:root>       ...     </my:root>   </xforms:instance>   <xforms:instance  src="/books/2/308/1/html/2/scripts/getuserid"/>   ...   <xforms:bind nodeset="my:root/..."/>   <xforms:bind nodeset="instance('userid')/..."/>   ... </xforms:model>

A similar problem to having multiple models occurs when you try to write a XPath expression that reaches across instances. By default, XPath expressions will always point into the first instance. The function instance( ), which takes an IDREF of an instance element, resets the XPath context to a different instance (but always within the same XForms Model).



XForms Essentials
Xforms Essentials
ISBN: 0596003692
EAN: 2147483647
Year: 2005
Pages: 117
Authors: Micah Dubinko

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net