5.5 Property readonly for Controlling Changes

5.5 Property readonly for Controlling Changes

XForms controls bound to the instance data make it possible to modify the values stored in the instance. Property readonly makes it possible to create dynamic applications where the user is allowed to change certain values only if some other condition holds true. Property readonly takes an XPath expression that evaluates to a boolean value. All nodes in the instance start off with property readonly set to true. The expression for the value of property readonly for a given node is recomputed whenever the nodes that the property depends on are modified.

5.5.1 Conditional Editing Using readonly

We illustrate the use of property readonly with an XForms interface that enables conditional editing of portions of an XML document. Consider the model shown in Figure 5.7.

Figure 5.7 Property readonly can temporarily prevent editing of certain fields.
 <  model   xmlns  ="http://www.w3.org/2002/xforms"> <  instance  > <  root   xmlns  =""> <  c1  ><  c11  /><  c12  /></  c1  > <  c2  ><  c21  /><  c22  /></  c2  > </  root  ></  instance  > <  bind   nodeset  ="/root"> <  bind   nodeset  ="c1/c12"  readonly  ="c1/c11&gt;10 and c1/c11&lt;100"/> </  bind  ></  model  > 

Property readonly is attached to node c1/c12 . The value is computed by evaluating an XPath expression

 c1/c11 &gt; 10 

which evaluates to true if and only if value of c1/c11 is greater than 10. Notice that when writing the comparison operator within an XPath expression, we need to use XML character entity &gt; .

XForms user interface controls that bind to field c1/c12 will reflect the state of property readonly ; for example, a visual browser might style the controls to indicate that the value may not be edited. Attempting to edit c12 when readonly is true would result in the XForms user agent signaling an error to the user with an appropriate message.

XForms. XML Powered Web Forms with CD
XForms. XML Powered Web Forms with CD
Year: 2003
Pages: 94

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