Webx3支持服務器端驗證,目前還不支持客戶端驗證。服務器端驗證配置在form.xml中,配置大體以下:spring
- <?xml version="1.0" encoding="UTF-8"?>
- <beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:services="http://www.alibaba.com/schema/services"
- xmlns:fm-conditions="http://www.alibaba.com/schema/services/form/conditions"
- xmlns:fm-validators="http://www.alibaba.com/schema/services/form/validators"
- xmlns="http://www.alibaba.com/schema/services/form/validators"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="
- http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
- http://www.alibaba.com/schema/services/form/conditions http://localhost:8080/schema/services-form-conditions.xsd
- http://www.alibaba.com/schema/services/form/validators http://localhost:8080/schema/services-form-validators.xsd
- http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
- ">
- <services:form postOnlyByDefault="true">
- <!--
- - ===============================================
- - 用來檢查csrf token。
- - ===============================================
- -->
- <services:group name="csrfCheck">
- <services:field name="csrfToken">
- <csrf-validator>
- <message>提交的數據已過時</message>
- </csrf-validator>
- </services:field>
- </services:group>
- <!--
- - ===============================================
- - Simple form
- - ===============================================
- -->
- <services:group name="simple" extends="csrfCheck">
- <services:field name="name" displayName="你的名字">
- <required-validator>
- <message>必須填寫 ${displayName}</message>
- </required-validator>
- </services:field>
- </services:group>
- </services:form>
- </beans:beans>
Webx2中以下:服務器
- <?xml version="1.0" encoding="GB18030"?>
- <form>
- <group name="register">
- <field name="id" displayName="用戶ID">
- <required-validator>
- <message>必須填寫${displayName}</message>
- </required-validator>
- <regexp-validator pattern="^[A-Za-z_][A-Za-z_0-9]*$">
- <message>${displayName}必須由字母、數字、下劃線構成</message>
- </regexp-validator>
- <length-validator minLength="4" maxLength="10">
- <message>${displayName}最少必須由${minLength}個字組成,最多不能超過${maxLength}個字</message>
- </length-validator>
- </field>
- </group>
- </form>