理解XForm——学习IBM DW的资料 (3)

1、XForm灵活的客户端数据校验功能

> 数据验证一般包括三种类型: > > * 完整性(Completeness): 用户必须填充所有要求的字段。有时候,某个字段是否必须填充依赖于另一个字段的值。比如,只有当用户使用信用卡支付时才需要信用卡号。 > * 数据类型(Data types): 数字必须是数字、日期必须是日期,依次类推。 > * 合理性(Appropriateness): 电话号码应该只包含数字,或者还可以包含与区号有关的短线和括号。邮政编码必须有 5 个数字组成,还可以带有短线和“加四”号码。 >

> > XForm提供Model中数据节点的类型绑定机制,如: > >

 1<xforms:model id="“payinfo“">
 2&gt; 
 3&gt; <xforms:submission action="http://www.andsky.com/orderform.php">  method="post"/&gt;   
 4&gt;  <xforms:instance xmlns="">   
 5&gt;  &lt; **paymentinfo** &gt;   
 6&gt;  <method></method>   
 7&gt;  <cardtype></cardtype>   
 8&gt;  <cardnumber></cardnumber>   
 9&gt;  <expdate></expdate>   
10&gt;  <!-- **paymentinfo** -->   
11&gt;  </xforms:instance>
12&gt; 
13&gt; ** <xforms:bind ref="paymentinfo" type="ccnumber"></xforms:bind> **   
14&gt;  ** <xsd:schema> **   
15&gt;  ** <xsd:simpletype name="ccnumber"> **   
16&gt;  ** <xsd:restriction base="xsd:string"> **   
17&gt;  ** <xsd:pattern value="\d{14,18}"></xsd:pattern> **   
18&gt;  ** </xsd:restriction> **   
19&gt;  ** </xsd:simpletype> **   
20&gt;  ** </xsd:schema> **
21&gt; 
22&gt; ** </xforms:submission></xforms:model>

**

** 2、强制输入 **

> ...
> >

 1<xforms:bind ref="paymentinfo/cardnumber">  **required="true()"**   
 2&gt;  type="ccnumber"/&gt;   
 3&gt;     
 4&gt;  ... 
 5
 63、带条件的强制输入 
 7
 8&gt; 如只有当用户选择信用卡支付时才要求输入信用卡号: 
 9&gt; 
10&gt; ...   
11&gt;     
12&gt;  <xforms:bind ref="paymentinfo/cardnumber">  **relevant="paymentinfo/method = 'cc'"**   
13&gt;  required="true()"   
14&gt;  type="ccnumber"/&gt;   
15&gt;    
16&gt;  
17
184、只读字段 
19
20&gt; 如“单价”字段不允许修改 
21&gt; 
22&gt; ...   
23&gt;     
24&gt;     
25&gt;  ** <xforms:bind ref="order/soaps/item/unitprice">  readonly="true()"/&gt; **   
26&gt;     
27&gt;  ... 
28
295、计算字段 
30
31&gt; 如“总价”=数量 * 单价:   
32&gt;  ...   
33&gt;     
34&gt;     
35&gt;  <xforms:bind readonly="true()" ref="order/soaps/item/unitprice"></xforms:bind>   
36&gt;  ** <xforms:bind **="" ref="order/soaps/item/totalprice">  **calculate="../qty * ../unitprice"/ &gt; **   
37&gt;     
38&gt;  ...   
39&gt; 
40
416、bind元素的其它属性 
42
43&gt;   * ` constraint ` :该属性设置任意的约束。比如,开发人员可以限制某个节点比另一个小。 
44&gt;   * ` maxOccurs ` 和 ` minOccurs ` :这两个属性确定表单中可以出现多少个项。 
45&gt;   * ` p3ptype ` :该属性把一个节点绑定到用户私有工作文件中的信息。 
46&gt;</xforms:bind></xforms:bind></xforms:bind></xforms:bind>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus