The problem can be split into two parts:
How do i override a framework error message?
What is the list of all possible error messages that can be generated by the JSF framework?
Part 1: OVERRIDING FRAMEWORK'S ERROR MESSAGES
In my project, under WebContent\WEB-INF, there is faces-config.xml, which contains <message-bundle>resources</message-bundle>
. 'resources' points to src\resources.properties. In this .properties file, i just have to add the corresponding entries, like
javax.faces.converter.DateTimeConverter.DATE={2}: ''{0}'' non poteva essere inteso come una data.
Should such error be generated by the application, the translated message will be displayed.
However, as i understand from Cannot override validation error message, the use of a resources.properties file under src is maven specific. Different packaging technologies may require different solutions.
Part 2: LIST OF ALL ERROR MESSAGES
Taking a look at the files contained in javax.faces.jar http://www.java2s.com/Code/Jar/j/Downloadjavaxfacesjar.htm , i see the following packages:
javax.faces.application
javax.faces.bean
javax.faces.component
javax.faces.context
javax.faces.convert
javax.faces.el
javax.faces.event
javax.faces.lifecycle
javax.faces.model
javax.faces.render
javax.faces.validator
javax.faces.view
javax.faces.webapp
For every class in each of these packages, i have to add entries in the resources.properties for every error that this class might raise.
But what are the errors that a class might raise? And what should the entry in the resource.properties look like?
I let myself guided by the entries that I've found in the Messages.properties file inside the jboss-jsf-api_2.1_spec-2.1.28.Final-redhat-1.jar (which I've mentioned in the question). It has the following entries, among many others:
# ==============================================================================
# Component Errors
# ==============================================================================
javax.faces.component.UIInput.CONVERSION={0}: Conversion error occurred.
javax.faces.component.UIInput.REQUIRED={0}: Validation Error: Value is required.
javax.faces.component.UIInput.UPDATE={0}: An error occurred when processing your submitted information.
In my IDE (eclipse), i click on an import statement import javax.faces.component.UIInput;
to navigate to UIInput.class . In the Class File Editor , i have the following lines :
// Field descriptor #193 Ljava/lang/String;
public static final java.lang.String CONVERSION_MESSAGE_ID = "javax.faces.component.UIInput.CONVERSION";
// Field descriptor #193 Ljava/lang/String;
public static final java.lang.String REQUIRED_MESSAGE_ID = "javax.faces.component.UIInput.REQUIRED";
// Field descriptor #193 Ljava/lang/String;
public static final java.lang.String UPDATE_MESSAGE_ID = "javax.faces.component.UIInput.UPDATE";
I remark that the value of the String field is exactly the key that must be added in the resources.properties, like, for example, javax.faces.component.UIInput.CONVERSION.
For a new class, like, for example, javax.faces.validator.RegexValidator class, I will do the following: open it in class file editor, pick those fields whose name ends in _ID, like :
// Field descriptor #30 Ljava/lang/String;
public static final java.lang.String VALIDATOR_ID = "javax.faces.RegularExpression";
// Field descriptor #30 Ljava/lang/String;
public static final java.lang.String PATTERN_NOT_SET_MESSAGE_ID = "javax.faces.validator.RegexValidator.PATTERN_NOT_SET";
// Field descriptor #30 Ljava/lang/String;
public static final java.lang.String NOT_MATCHED_MESSAGE_ID = "javax.faces.validator.RegexValidator.NOT_MATCHED";
// Field descriptor #30 Ljava/lang/String;
public static final java.lang.String MATCH_EXCEPTION_MESSAGE_ID = "javax.faces.validator.RegexValidator.MATCH_EXCEPTION";
and add the following entries to the resources.properties file:
javax.faces.RegularExpression=custom message
javax.faces.validator.RegexValidator.PATTERN_NOT_SET=custom message
javax.faces.validator.RegexValidator.NOT_MATCHED=custom message
javax.faces.validator.RegexValidator.MATCH_EXCEPTION=custom message
Unfortunately, given the huge number of classes for which error messages must be provided, i don't find this as a feasible solution.
UPDATE
I just realized why only Conversion and Validation error messages should be provided: because they are related to user input, which the programmer cannot control. All the other errors like Navigation related issues must be properly handled by the programmer. Such errors should not appear in the first place, so it does not make sense to translate those messages anyway.