More JSF Validation - Custom Error Messages
The errors messages that are shown for each type of validation error are controlled by the Message.properties file, which is located in the javax.faces package of jsf-impl.jar. You can view this file by expanding Libraries > Sun Java System Application Server > jsf-impl.jar > javax.faces and double-clicking Message.properties.
If you want to create custom messages for these errors, you can do so by swapping out the properties file used by the application.
- Right-click the jAstrologer project and choose New > File/Folder. Under the Other category, select Properties File and click Next. Name the file MyMessages, put it in the src/astrologer/ui folder, and click Finish. MyProperties.properties opens in the Source Editor.
- Copy over the following properties from Message.properties to MyProperties.properties:
javax.faces.component.UIInput.REQUIRED={0}: Validation Error: Value is required. javax.faces.converter.DateTimeConverter.DATE_detail={2}: ''{0}'' could not be understood as a date. Example: {1} - Change the values of the properties:
javax.faces.component.UIInput.REQUIRED=Please enter a value for this field. javax.faces.converter.DateTimeConverter.DATE=Please enter a valid date. javax.faces.converter.DateTimeConverter.DATE_detail=Please enter a valid date. Example: {1} - Open faces-config.xml (under the Configuration Files node) and enter the
following inside the main faces-config element:
... <application> <locale-config> <default-locale>en</default-locale> </locale-config> <message-bundle>astrologer.ui.MyMessages</message-bundle> </application> </faces-config> - Right-click the application and choose Run Project. When you do not enter
anything for a required field or enter a bad date format for the birthday
field, the application now shows the following errors:

Note that any messages that you haven't specified in your custom properties file will be taken from the default Message.properties in jsf-impl.jar. Also, you can define a CSS style for error messages and then specify that style in the message tag by doing the following:
<h:message for="birthday" style="errorMessage" /></p>