JSF国际化

来源:互联网 发布:网络层 编辑:程序博客网 时间:2024/05/16 04:35

 <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类型

==========================================================
为了方便,将以下内容复制你的资源文件,如:messages_zh_CN.properties中
#####################################################################################
#Standard JSF error message KEY and TEXT
#/u6807/u51c6JSF/u9519/u8bef/u4fe1/u606fKEY/u4e0eTEXT
#Create by qing2000(qing2000@126.com)   2007-09-06
#------------------------------------------------------------------------------------
javax.faces.validator.NOT_IN_RANGE={2}/u6307/u5b9a/u5c5e/u6027/u503c/u4e0d/u5728[0}/uff0c{1}]/u8303/u56f4/u5185
javax.faces.validator.NOT_IN_RANGE_detail={2}/u503c/u5fc5/u987b/u4ecb/u4e8e[{0}/uff0c{1}]/u4e4b/u95f4
javax.faces.validator.DoubleRangeValidator.LIMIT={0}/u8d85/u8fc7/u4e86double/u7c7b/u578b/u7684/u6781/u9650
javax.faces.validator.DoubleRangeValidator.MAXIMUM={1}/u5927/u4e8e/u4e86/u5141/u8bb8/u7684/u6700/u5927/u503c/u201c{0}/u201d
javax.faces.validator.DoubleRangeValidator.MINIMUM={1}/u5c0f/u4e8e/u4e86/u5141/u8bb8/u7684/u6700/u5c0f/u503c/u201c{0}/u201d
javax.faces.validator.DoubleRangeValidator.TYPE={0}/u4e0d/u662f/u6709/u6548/u7684double/u7c7b/u578b
javax.faces.validator.LengthValidator.LIMIT={0}/u8d85/u8fc7/u4e86/u5b57/u7b26/u6781/u9650
javax.faces.validator.LengthValidator.MAXIMUM={1}/u957f/u5ea6/u5927/u4e8e/u4e86/u5141/u8bb8/u7684/u6700/u5927/u503c/u201c{0}/u201d
javax.faces.validator.LengthValidator.MINIMUM={1}/u957f/u5ea6/u5c0f/u4e8e/u4e86/u5141/u8bb8/u7684/u6700/u5c0f/u503c/u201c{0}/u201d
javax.faces.component.UIInput.CONVERSION=/u6570/u636e/u8f6c/u6362/u9519/u8bef
javax.faces.component.UIInput.REQUIRED={0}/u662f/u5fc5/u586b/u9879
javax.faces.component.UISelectOne.INVALID={0}/u9009/u62e9/u5185/u5bb9/u65e0/u6548
javax.faces.component.UISelectMany.INVALID={0}/u9009/u62e9/u5185/u5bb9/u65e0/u6548
javax.faces.validator.RequiredValidator.FAILED={0}/u662f/u5fc5/u586b/u9879.
javax.faces.validator.LongRangeValidator.LIMIT={0}

原创粉丝点击