Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom error messages in JSF validators?

 
Namitha karupaiya
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I put my custom error messages for JSF built-in validators?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You normally specify the validation message as the text of the ValidationException thrown by the validator. However, you can override this on the validator tag itself and display whatever text you want to for the element being validated.
 
Namitha karupaiya
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to override the error message from a built-in validator (ex: valueRequired validator) globally? That means if I make some changes in the web.xml or faces-config.xml, I will have my custom message for this validator in all my JSF pages.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "required=" attribute is a special case, since it's built into tags instead of applied as a sub-element. Yes, you can override this message.

I don't remember the details, but I think they're pretty easy to dig up. The same mechanism also permits overriding the more conventional (element-defined) standard validators.
 
suresh dasari
Ranch Hand
Posts: 121
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the following code in faces-config.xml file and write your own properties file with name xxxxxxMessages.properties
but make sure to use the same error code/Id for user defined property file and give whatever the description you want.

 
Namitha karupaiya
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks suresh dasari !

Where should I place this xxxxxxMessages.properties file in my project?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic