Webx服务器端验证

 

  Webx3支持服务器端验证,目前还不支持客户端验证。服务器端验证配置在form.xml中,配置大体以下:spring

  
  
           
  
  
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3.     xmlns:services="http://www.alibaba.com/schema/services" 
  4.     xmlns:fm-conditions="http://www.alibaba.com/schema/services/form/conditions" 
  5.     xmlns:fm-validators="http://www.alibaba.com/schema/services/form/validators" 
  6.     xmlns="http://www.alibaba.com/schema/services/form/validators" 
  7.     xmlns:beans="http://www.springframework.org/schema/beans" 
  8.     xmlns:p="http://www.springframework.org/schema/p" 
  9.     xsi:schemaLocation=" 
  10.         http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd 
  11.         http://www.alibaba.com/schema/services/form/conditions http://localhost:8080/schema/services-form-conditions.xsd 
  12.         http://www.alibaba.com/schema/services/form/validators http://localhost:8080/schema/services-form-validators.xsd 
  13.         http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd 
  14.     "> 
  15.  
  16.     <services:form postOnlyByDefault="true"> 
  17.         <!-- 
  18.           - =============================================== 
  19.           - 用来检查csrf token。 
  20.           - =============================================== 
  21.          --> 
  22.         <services:group name="csrfCheck"> 
  23.             <services:field name="csrfToken"> 
  24.                 <csrf-validator> 
  25.                     <message>提交的数据已过时</message> 
  26.                 </csrf-validator> 
  27.             </services:field> 
  28.         </services:group> 
  29.         <!-- 
  30.           - =============================================== 
  31.           - Simple form 
  32.           - =============================================== 
  33.          --> 
  34.         <services:group name="simple" extends="csrfCheck"> 
  35.             <services:field name="name" displayName="你的名字"> 
  36.                 <required-validator> 
  37.                     <message>必须填写 ${displayName}</message> 
  38.                 </required-validator> 
  39.             </services:field> 
  40.         </services:group> 
  41.     </services:form> 
  42.  
  43. </beans:beans> 

Webx2中以下:服务器

  
  
           
  
  
  1. <?xml version="1.0" encoding="GB18030"?> 
  2. <form> 
  3.     <group name="register"> 
  4.         <field name="id" displayName="用户ID"> 
  5.             <required-validator> 
  6.                 <message>必须填写${displayName}</message> 
  7.             </required-validator> 
  8.             <regexp-validator pattern="^[A-Za-z_][A-Za-z_0-9]*$"> 
  9.                 <message>${displayName}必须由字母、数字、下划线构成</message> 
  10.             </regexp-validator> 
  11.             <length-validator minLength="4" maxLength="10"> 
  12.                 <message>${displayName}最少必须由${minLength}个字组成,最多不能超过${maxLength}个字</message> 
  13.             </length-validator> 
  14.         </field> 
  15.     </group> 
  16. </form>