星期二, 十二月 27, 2005

如何改变JSF默认的错误提示信息.

在JSF 规范里给出的错误提示字典如下:
javax.faces.Message.properties 里.这是Sun JSF IMPL实现里的资源.

myfaces相应的资源名可能有不同.


# ==============================================================================
# SPECIFICATION DEFINED MESSAGES
# ==============================================================================


# ==============================================================================
# Component Errors
# ==============================================================================

javax.faces.component.UIInput.CONVERSION={0}Conversion error occurred.
javax.faces.component.UIInput.REQUIRED=Validation Error\: {0}Value is required.
javax.faces.component.UISelectOne.INVALID=Validation Error\: {0}Value is not valid
javax.faces.component.UISelectMany.INVALID=Validation Error\: {0}Value is not valid

# ==============================================================================
# Validator Errors
# ==============================================================================

javax.faces.validator.NOT_IN_RANGE=Validation Error\: {2}Specified attribute is not between the expected values of {0} and {1}.
javax.faces.validator.DoubleRangeValidator.MAXIMUM=Validation Error\: {1}Value is greater than allowable maximum of "{0}"
javax.faces.validator.DoubleRangeValidator.MINIMUM=Validation Error\: {1}Value is less than allowable minimum of ''{0}''
javax.faces.validator.DoubleRangeValidator.TYPE=Validation Error\: {0}Value is not of the correct type
javax.faces.validator.LengthValidator.MAXIMUM=Validation Error\: {1}Value is greater than allowable maximum of ''{0}''
javax.faces.validator.LengthValidator.MINIMUM=Validation Error\: {1}Value is less than allowable minimum of ''{0}''
javax.faces.validator.LongRangeValidator.MAXIMUM=Validation Error\: {1}Value is greater than allowable maximum of ''{0}''
javax.faces.validator.LongRangeValidator.MINIMUM=Validation Error\: {1}Value is less than allowable minimum of ''{0}''
javax.faces.validator.LongRangeValidator.TYPE=Validation Error\: "{0}" Value is not of the correct type.


# ==============================================================================
# IMPLEMENTATION DEFINED MESSAGES
# ==============================================================================

com.sun.faces.ASSERTION_FAILED=Assertion Failed
com.sun.faces.ATTRIBUTE_NOT_SUPORTED=Attribute ''{0}'' not supported for component type ''{1}''.
com.sun.faces.CANT_CONVERT_VALUE=Can''t convert property: ''{0}'' to value type: ''{1}''.
com.sun.faces.CANT_CLOSE_INPUT_STREAM=Unable to close input stream.
com.sun.faces.CANT_CREATE_LIFECYCLE_ERROR=Can''t create Lifecycle for id: ''{0}''.
com.sun.faces.CANT_INSTANTIATE_CLASS=Can''t instantiate class: ''{0}''.
com.sun.faces.CANT_INTROSPECT_CLASS=Can''t introspect class: ''{0}''
com.sun.faces.CANT_PARSE_FILE=Can''t parse file: ''{0}''.
com.sun.faces.COMPONENT_NOT_FOUND_ERROR=Component Not Found for identifier: ''{0}''.
com.sun.faces.COMPONENT_NOT_FOUND_IN_VIEW_WARNING=Unable to find component with ID ''{0}'' in view.
com.sun.faces.CONTENT_TYPE_ERROR=Unrecognized Content Type.
com.sun.faces.CONVERTER_NOT_FOUND_ERROR=Converter Not Found for identifier: ''{0}''.
com.sun.faces.DUPLICATE_COMPONENT_ID_ERROR=Duplicate component ID ''{0}'' found in view.
com.sun.faces.EMPTY_PARAMETER=Parameter is empty
com.sun.faces.ENCODING_ERROR=Unrecognized Character Encoding.
com.sun.faces.ERROR_GETTING_VALUE_BINDING=Can''t get ValueBinding for value: ''{0}''.
com.sun.faces.ERROR_GETTING_VALUEREF_VALUE=Can''t get value from value binding expression: ''{0}''.
com.sun.faces.ERROR_OPENING_FILE=Can''t open configuration file: ''{0}''.
com.sun.faces.ERROR_REGISTERING_DTD=Can''t register DTD: ''{0}''.
com.sun.faces.ERROR_SETTING_BEAN_PROPERTY=Can''t set managed bean property: ''{0}''.
com.sun.faces.FACES_CONTEXT_CONSTRUCTION_ERROR=Construction Error: One or more input parameters may be null.
com.sun.faces.FACES_SERVLET_MAPPING_CANNOT_BE_DETERMINED=Unable to determine FaceServlet mapping for servlet path ''{0}''.
com.sun.faces.FILE_NOT_FOUND=File Not Found for file: ''{0}''.
com.sun.faces.ILLEGAL_ATTEMPT_SETTING_STATEMANAGER=Illegal attempt to set StateManager after a response has been generated.
com.sun.faces.ILLEGAL_ATTEMPT_SETTING_VIEWHANDLER=Illegal attempt to set ViewHandler after a response has been generated.
com.sun.faces.ILLEGAL_CHARACTERS_ERROR=Characters not allowed.
com.sun.faces.ILLEGAL_IDENTIFIER_LVALUE_MODE=Illegal use of implicit object identifier in lValue mode: ''{0}''
com.sun.faces.ILLEGAL_MODEL_REFERENCE=Illegal Model Reference in this context for expression ''{0}''.
com.sun.faces.ILLEGAL_VIEW_ID=Illegal view ID ''{0}''. The ID must begin with ''/''
com.sun.faces.INVALID_EXPRESSION=Invalid expression: ''{0}''.
com.sun.faces.INVALID_INIT_PARAM=Invalid initialization parameter: ''{0}''.
com.sun.faces.INVALID_MESSAGE_SEVERITY_IN_CONFIG=Invalid Message severity ''{0}'' defined in configuration.
com.sun.faces.INVALID_SCOPE_LIFESPAN=The scope of the referenced object: ''{0}'' is shorter than the referring object
com.sun.faces.LIFECYCLE_ID_ALREADY_ADDED=LifecycleId already added for id: ''{0}''.
com.sun.faces.LIFECYCLE_ID_NOT_FOUND=LifecycleId not found for id ''{0}''.
com.sun.faces.MAXIMUM_EVENTS_REACHED=Maximum number of events ''{0}'' reached.
com.sun.faces.MISSING_CLASS_ERROR=Missing Class: Can''t load class ''{0}''.
com.sun.faces.MISSING_RESOURCE_ERROR=Missing Resource: Can''t get ResourceBundle.
com.sun.faces.MODELUPDATE_ERROR=Model Update failure for value ''{0}'' in model''{1}''.
com.sun.faces.NAMED_OBJECT_NOT_FOUND_ERROR=Expression Error: Named Object: ''{0}'' not found.
com.sun.faces.NOT_NESTED_IN_FACES_TAG_ERROR=Not nested in a UIComponentTag Error for tag with handler class: ''{0}''.
com.sun.faces.NULL_BODY_CONTENT_ERROR=BodyContent is null for tag with handler class: ''{0}''.
com.sun.faces.NULL_COMPONENT_ERROR=Construction Error: Component argument is null.
com.sun.faces.NULL_CONFIGURATION=No Configuration loaded for the application.
com.sun.faces.NULL_CONTEXT_ERROR=Argument Error: Context argument is null.
com.sun.faces.NULL_EVENT_ERROR=Argument Error: Event argument is null.
com.sun.faces.NULL_FORVALUE=Component "{0}" not found
com.sun.faces.NULL_HANDLER_ERROR=Argument Error: Handler argument is null.
com.sun.faces.NULL_LOCALE_ERROR=Argument Error: Locale argument is null.
com.sun.faces.NULL_MESSAGE_ERROR=Argument Error: Message parameter cannot be null
com.sun.faces.NULL_PARAMETERS_ERROR=Argument Error: One or more parameters are null.
com.sun.faces.NULL_REQUEST_VIEW_ERROR=Argument Error: Request View argument is null.
com.sun.faces.NULL_RESPONSE_STREAM_ERROR=Argument Error: ResponseStream argument is null.
com.sun.faces.NULL_RESPONSE_VIEW_ERROR=Argument Error: ResponseView argument is null.
com.sun.faces.NULL_RESPONSE_WRITER_ERROR=Argument Error: ResponseWriter argument is null.
com.sun.faces.OBJECT_CREATION_ERROR=One or more confgured application objects could not be created. Check your web application logs for details.
com.sun.faces.PHASE_ID_OUT_OF_BOUNDS=PhaseId out of bounds for id: ''{0}''.
com.sun.faces.RENDERER_NOT_FOUND=Renderer not found for Renderer type: ''{0}''.
com.sun.faces.REQUEST_VIEW_ALREADY_SET_ERROR=State Error: RequestView has already been set for this request.
com.sun.faces.SAVING_STATE_ERROR=Error while saving state in ''{0}'': ''{1}''.
com.sun.faces.SUPPORTS_COMPONENT_ERROR=Argument Error: ''{0}'' is not supported for this renderer.
com.sun.faces.TYPECONVERSION_ERROR="{2}" Conversion Error setting value ''{0}'' for ''{1}''.
com.sun.faces.VALIDATION_COMMAND_ERROR=Validation error. ''{0}'' must have value or image attribute.
com.sun.faces.VALIDATION_EL_ERROR=Validation error. Expression invalid for:''{0}''
com.sun.faces.VALIDATION_ID_ERROR=Validation error. The following JSF tags are required to contain IDs:''{0}''
com.sun.faces.VALIDATOR_NOT_FOUND_ERROR=Validator Not Found for identifier: ''{0}''.


com.sun.faces.CYCLIC_REFERENCE_ERROR=Possible cycle reference to managed bean "{0}"


修改为自己的本地语言的 必须要设置.
web.xml里设置的:
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

faces-config.xml
文件里的配置部分,如下:

<faces-config>
<application>
<locale-config>
<default-locale>zh</default-locale>
</locale-config>
<message-bundle>org.wxk.HelloWorld</message-bundle>
</application>
</faces-config>