国际化JSF验证中错误消息

来源:互联网 发布:wifi摄像头监控软件 编辑:程序博客网 时间:2024/06/05 05:47

比如:<f:inputText ... required="true" />如果为空提交,会报“Validation Error: Value is required.”错误。

如果我要国际化怎么做?

1.在资源文件message_zh_CN.properties和message_语言_国家.properties文件

2.配置faces-config.xml

<application>

    <message-bundle>myvalidate.message</message-bundle>

    <locale-config>

      <default-locale>zh_CN</default-locale>    <!--默认资源文件-->

      <supported-locale>en</supported-locale>    <!--支持的资源文件-->

      <supported-locale>en_IE</supported-locale>   <!--支持的资源文件-->

    </locale-config>

</application>

3.在资源文件中建立一个KEY和Value,当然Value需要转成Unicode码。

javax.faces.component.UIInput.REQUIRED=错误信息:必填项

看看是不是成功了?

下面我把默认错误都列出来,只要制作一个就是国际化的错误消息了。

---------------------------------------------------------------------------

标准JSF错误信息KEY与TEXT

javax.faces.validator.NOT_IN_RANGE

Validation Error: Specified attribute is not between the expected values of {0} and {1}.

错误信息:指定属性值不在[{0},{1}]范围内

javax.faces.validator.NOT_IN_RANGE_detail

The value must be between {0} and {1}.

值必须介于[{0},{1}]之间

javax.faces.validator.DoubleRangeValidator.LIMIT

Validation Error: Specified attribute cannot be converted to proper type.

错误信息:指定属性值超过了double类型的极限

javax.faces.validator.DoubleRangeValidator.MAXIMUM

Validation Error: Value is greater than allowable maximum of ‘‘{0}’’.

错误信息:值大于了允许的最大值“{0}”

javax.faces.validator.DoubleRangeValidator.MINIMUM

Validation Error: Value is less than allowable minimum of ‘‘{0}’’.

错误信息:值小于了允许的最小值“{0}”

javax.faces.validator.DoubleRangeValidator.TYPE

Validation Error: Value is not of the correct type.

错误信息:值不是有效的double类型

javax.faces.validator.LengthValidator.LIMIT

Validation Error: Specified attribute cannot be converted to proper type.

错误信息:指定属性值超过了字符极限

javax.faces.validator.LengthValidator.MAXIMUM

Validation Error: Value is greater than allowable maximumof ‘‘{0}’’.

错误信息:值长度大于了允许的最大值“{0}”

javax.faces.validator.LengthValidator.MINIMUM

Validation Error: Value is less than allowable minimumof ‘‘{0}’’.

错误信息:值长度小于了允许的最小值“{0}”

javax.faces.component.UIInput.CONVERSION

Conversion error during model data update

模型数据更新期间转换错误(字面翻译)

javax.faces.component.UIInput.REQUIRED

Validation Error: Value is required.

错误信息:必填项

javax.faces.component.UISelectOne.INVALID

Validation Error: Value is not valid.

错误信息:选择内容无效

javax.faces.component.UISelectMany.INVALID

Validation Error: Value is not valid.

错误信息:选择内容无效

javax.faces.validator.RequiredValidator.FAILED

Validation Error: Value is required.

错误信息:必填项

javax.faces.validator.LongRangeValidator.LIMIT

Validation Error: Specified attribute cannot be converted to proper type.

错误信息:指定属性值超过了long类型的极限

javax.faces.validator.LongRangeValidator.MAXIMUM

Validation Error: Value is greater than allowable maximum of ‘‘{0}’’.

错误信息:值大于了允许的最大值“{0}”

javax.faces.validator.LongRangeValidator.MINIMUM

Validation Error: Value is less than allowable minimum of ‘‘{0}’’.

错误信息:值小于了允许的最小值“{0}”

javax.faces.validator.LongRangeValidator.TYPE

Validation Error: Value is not of the correct type.

错误信息:不是有效的long类型

原创粉丝点击