Customize validation error message in JSF 2.0

The standard JSF conversion and validation error messages are too detail, technical or sometime, not really human readable. In this article, it shows you how to customize standard conversion or validation error message in JSF 2.0.

Summary Guide

  1. Find your message key from jsf-api-2.x.jar, “” file.
  2. Create your own properties file, and put the same message key you found in above “” file, and override it with your custom error message.
  3. Register your properties file in “faces-config.xml”, put it as application level.
  4. Done.


All JSF standard conversion and validation error messages are stored in “” file, which can be located from jsf-api-2.x.jar, “javax\faces\“, see figure below :


See portion of this “” file

# ===================================================================
# Converter Errors
# ===================================================================
javax.faces.converter.DateTimeConverter.DATE={2}: ''{0}'' could not be understood as a date.
javax.faces.converter.DateTimeConverter.DATE_detail={2}: ''{0}'' could not be understood as a date. Example: {1} 
# ====================================================================
# Validator Errors
# ====================================================================
javax.faces.validator.LengthValidator.MAXIMUM={1}: Validation Error: Length is greater than allowable maximum of ''{0}''
javax.faces.validator.LengthValidator.MINIMUM={1}: Validation Error: Length is less than allowable minimum of ''{0}''

For example,
1. <f:validateLength minimum=”5″ maximum=”10″ />
If maximum length validation failed, JSF gets “javax.faces.validator.LengthValidator.MAXIMUM”.
If minimum length validation failed, JSF gets “javax.faces.validator.LengthValidator.MINIMUM”.

2. <f:convertDateTime pattern=”d-M-yyyy” />
If date validation failed, JSF gets “javax.faces.converter.DateTimeConverter.DATE_detail”.

If you do not sure which key match to which validator tag, just display the error message once and compare it with “”, then you will know which key you want to override.

2. Custom Error Message

Create a properties file named “” (can be any name you like), put message key and custom error message inside. Later, put this properties file into your project resources folder.

javax.faces.converter.DateTimeConverter.DATE={2}: ''{0}'' could not be understood as a date.
javax.faces.converter.DateTimeConverter.DATE_detail=Invalid date format.
javax.faces.validator.LengthValidator.MINIMUM=Minimum length of ''{0}'' is required.

Now, you are going to custom the validation error message for “javax.faces.validator.LengthValidator.MINIMUM” and conversion error message for “javax.faces.converter.DateTimeConverter.DATE_detail“.

For the XXX_detail message key, you have to override its parent key (summary message) as well, which is XXX without the “_detail” behind; Otherwise, JSF will ignore your new custom error message and keep getting the standard error message from “”, may be this is a bug in JSF 2.0?

3. Register Message Bundle

Register your custom properties file in “faces-config.xml”, put it as Application level.


<?xml version="1.0" encoding="UTF-8"?>

4. Demo

A JSF page, add both <f:validateLength /> and <f:convertDateTime /> validation.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""   
    	<h1>Customize validation error message in JSF 2.0</h1>
		<h:panelGrid columns="3">
			Enter your username :
			<h:inputText id="username" value="#{user.username}" 
				size="20" required="true" label="Username">
				<f:validateLength minimum="5" maximum="10" />
			<h:message for="username" style="color:red" />
			Enter your DOB :
			<h:inputText id="dob" value="#{user.dob}" 
				size="20" required="true" label="Date of Birth">
				<f:convertDateTime />
			<h:message for="dob" style="color:red" />
		<h:commandButton value="Submit" action="result" />

When validation failed, display your custom error message now.


Download Source Code


  1. JSF 2 & Resource Bundle
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Pingback: alkaline water brands()

  • Pingback: pay per day loans plan()

  • Pingback: Instagram likes kopen()

  • Pingback: laan penge()

  • Pingback: alkaline water benefits()

  • Pingback: car parking()

  • Pingback: water ionizers()

  • Pingback: parking()

  • Pingback: fue()

  • Pingback: lane penge nu()

  • Pingback: DIRECTV Satellite Television()

  • Pingback: Direct TV vs Cable TV()

  • Pingback: Blue Coaster33()

  • Srikanth


    Both should be available .properties, only one of the property is not sufficient to override the default values

  • Jose

    As always Thanks!!!!!!!!!!!!!!!!!!

  • Saleh


    I just want to mention something.

    When I tried this tutorial I failed because of a little misconceiving regarding the file: project resources folder
    >>”. Later, put this properties file into your project resources folder.”

    I am using NetBeans and I thought it is “resources” (which can contain css files and others) and that causes the error message:
    Can’t find bundle for base name message, locale en_US

    So the correct place is in the “Source Packages” -> (NetBeans)

    I Know that you use Eclipse where the equivalent is “Java Resources” and you meant that.

    So I hope you to clarify it in a proper way.

    Finally Thank you for the great tutorials.

  • Murugan Subbiah

    I was looking for the exact blog. You rock. Thanks a lot.

  • Louise

    Just a side note to any one maybe not seeing their messages right away: Keep in mind that the h:messages attribute is by default configured as showDetails=”true” and showSummary=”false”. When you only override the non-suffixed key (which is used for summary) this will have no visible effect. Either change the attributes on your message component or also override the key suffixed with _detail.

  • Pingback: Proxy Servers » JSF – Addding custom validation messages is causing issue in loading css files from resources()

  • Andrejs82

    I am just put into my project resource file like /javax/faces/ and everything working!

  • Raj

    Can you please provide full list of keys that can be used.

    like for when we use match attribute of primeface password control which Error Key’d message is displayed.

  • hector

    hello, I did all the steps and I get the custom message, I can be wrong?

  • suni

    You are my HERO!! Thanks :)

  • kshitij

    Hello Mk Yong

    i have problem regarding to this error messages.

    i have two languages in project.

             &lt;h:outputText value=&quot;#{cm['username']}&quot; /&gt;
             &lt;p:inputText id=&quot;loginname&quot; value=&quot;#{simpleLogin.loginname}&quot; 
                  label=&quot;Username&quot; required=&quot;true&quot; maxlength=&quot;30&quot; /&gt;

    when i am submitting form with null value then it is printing message like

    “Username: Validation Error: Value is required.”

    problem is it is also printing same text for turkish language.

    How to get turkish text for “Username: Validation Error: Value is required.”

  • ??????????

    Thanks to the good things come to you.

  • Juan Carlos Vaca

    Hi, I customized the validation messages in my app which uses icefaces 1.8. We did something like this javax.faces.component.UIInput.REQUIRED=. When an error is presente, it presents a little image, and using java script, on mouse over the image, a Bubble apears showing the errors.

    Now I migrated my application to icefaces 20.2 and now the message errors is presented exatly as is defined in message bundle, The are escaped. Is there a way to avoid escape characters in icefaces 2.0?

    • mkyong

      Not familiar with icefaces, hope others around are able to answer your question. For non-related question please post at –

  • Pingback: JSF 2.0 Tutorials()