Struts2 客户端验证和国际化问题

Struts2客户端验证和国际化问题
国际化文件:myMessage_zh_CN.properties

在Struts.xml加载国际化资源文件
<constant name="struts.custom.i18n.resources" value="myMessage"></constant>

当在页面中<s:form action="register" validate="true">设为true时验证文件不能用<message key="password.required"></message>
而要用<message>${getText("password.required")}</message>

RegisterAction-validation.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC 
  		"-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
  		"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
	<field name="username">
		<field-validator type="requiredstring" short-circuit="true">
			<param name="trim">true</param>
			<message>${getText("username.required")}</message>
		</field-validator>

		<field-validator type="regex">
			<param name="expression"><![CDATA[(\w{6,20})]]></param>
			<message>${getText("username.rule")}</message>
		</field-validator>
	</field>

	<field name="password">
		<field-validator type="requiredstring" short-circuit="true">
			<param name="trim">true</param>
			<message>${getText("password.required")}</message>
		</field-validator>

		<field-validator type="regex">
			<param name="expression"><![CDATA[(\w{6,20})]]></param>
			<message>${getText("password.rule")}</message>
		</field-validator>
	</field>

	<field name="repassword">
		<field-validator type="requiredstring" short-circuit="true">
			<param name="trim">true</param>
			<message>${getText("repassword.required")}</message>
		</field-validator>

		<field-validator type="regex" short-circuit="true">
			<param name="expression"><![CDATA[(\w{6,20})]]></param>
			<message>${getText("repassword.rule")}</message>
		</field-validator>

		<field-validator type="fieldexpression">
			<param name="expression"><![CDATA[(repassword==password)]]></param>
			<message>${getText("repassword.equals")}</message>
		</field-validator>
	</field>

	<field name="age">
		<field-validator type="int">
			<param name="min">1</param>
			<param name="max">120</param>
			<message>${getText("age.rule")}</message>
		</field-validator>
	</field>

	<field name="birth">
		<field-validator type="date">
			<param name="min">1900-01-01</param>
			<param name="max">2010-01-01</param>
			<message>${getText("birth.rule")}</message>
		</field-validator>
	</field>

	<field name="email">
		<field-validator type="email">
			<message>${getText("email.rule")}</message>
		</field-validator>
	</field>
</validators>



其中short-circuit="true"可以消灭校验短路问题
但是客户端校验不支持校验器短路,暂时只能在服务器端校验中使用

你可能感兴趣的:(xml,验证,validators)