Webx3支持服务器端验证,目前还不支持客户端验证。服务器端验证配置在form.xml中,配置大致如下:
- <?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>
本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/683811,如需转载请自行联系原作者