1)
struts-doc-config.xml:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation_doc.xml" />
</plug-in>
2)
Make sure your form extends ValidatorActionForm or ValidatorForm.
3)验证类和验证方法(不是必须的,但要验证到方法一级的颗粒度验证方法必须自己写)
详见:com.huawei.it.mi.validator.MIFieldChecks
public static boolean validateRequired(
Object bean,
ValidatorAction va,
Field field,
ActionErrors errors,
HttpServletRequest request) {...}
4)
WEB-INF/validaotr-rules.xml
<validator name="mi.required" classname="com.huawei.it.mi.validator.MIFieldChecks" method="validateRequired" methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest" msg="errors.required">
</validator>
5)
确保资源文件里有:errors.required={0} is required.
6)
validation.xml里加入你要验证的action别名(注意这里是action的名字)
<form name="/frontDoc">
<field property="name" depends="mi.required">
<arg0 key="一线市场-标题" resource="false" />
<var>
<var-name>methodsNeedValidation</var-name>
<var-value>saveToDraft</var-value>
</var>
</field>
</form>
注:如果有多个方法你可以使用逗号分割符。如:<var-value>saveToDraft,publish</var-value>
7)
确保你的struts配置文件里相应的action里的各参数配置正确:
1、validate="true";
2、input="mi.document.frontDocError"你的显示错误的页面
3、error页面上有<html:errors/>
<action path="/frontDoc" type="com.huawei.it.mi.document.action.FrontDocAction" name="fronDocForm" scope="request" validate="true" input="mi.document.frontDocError" parameter="method">
<forward name="frontDocCreate" path="mi.document.frontDocCreate" />
<forward name="frontDocList" path="mi.document.frontDocList">
</forward>
<forward name="success" path="mi.document.frontDocSuccess">
</forward>
<forward name="error" path="mi.document.frontDocError">
</forward>
</action>
8) U can go!
struts-doc-config.xml:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation_doc.xml" />
</plug-in>
2)
Make sure your form extends ValidatorActionForm or ValidatorForm.
3)验证类和验证方法(不是必须的,但要验证到方法一级的颗粒度验证方法必须自己写)
详见:com.huawei.it.mi.validator.MIFieldChecks
public static boolean validateRequired(
Object bean,
ValidatorAction va,
Field field,
ActionErrors errors,
HttpServletRequest request) {...}
4)
WEB-INF/validaotr-rules.xml
<validator name="mi.required" classname="com.huawei.it.mi.validator.MIFieldChecks" method="validateRequired" methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest" msg="errors.required">
</validator>
5)
确保资源文件里有:errors.required={0} is required.
6)
validation.xml里加入你要验证的action别名(注意这里是action的名字)
<form name="/frontDoc">
<field property="name" depends="mi.required">
<arg0 key="一线市场-标题" resource="false" />
<var>
<var-name>methodsNeedValidation</var-name>
<var-value>saveToDraft</var-value>
</var>
</field>
</form>
注:如果有多个方法你可以使用逗号分割符。如:<var-value>saveToDraft,publish</var-value>
7)
确保你的struts配置文件里相应的action里的各参数配置正确:
1、validate="true";
2、input="mi.document.frontDocError"你的显示错误的页面
3、error页面上有<html:errors/>
<action path="/frontDoc" type="com.huawei.it.mi.document.action.FrontDocAction" name="fronDocForm" scope="request" validate="true" input="mi.document.frontDocError" parameter="method">
<forward name="frontDocCreate" path="mi.document.frontDocCreate" />
<forward name="frontDocList" path="mi.document.frontDocList">
</forward>
<forward name="success" path="mi.document.frontDocSuccess">
</forward>
<forward name="error" path="mi.document.frontDocError">
</forward>
</action>
8) U can go!