Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

replacing default validator message at h:messages

 
Pamungkas Timotius
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having this code




and a <h:messages> in corresponding JSP, can I replace default validator's message?

For example, instead of displaying "registerNewAccountFormOne:txtRequestedUserName: Validation Error: Value is less than allowable minimum of '6'", which will confusing for my end-users, can I display "user name too short (minimum 6 characters)"

Also, at the same time, can I customize validation for which attached on same input component (txtRequestedUSerName in this case).

Thanks..
 
David Heffelfinger
author
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pamungkas,

A custom error message for length validation can be achieved by creating a property file with a key of:



Then adding the following tags your faces-config.xml:



In the above example, replace com.mycompany with the correct package name, and MyMessageBundle with the file name you gave your property file.

A similar technique can be used for customizing the required field validation message.

This technique is covered in detail in my book, Java EE 5 Development With GlassFish Application Server

Hope that helps,
David
[ October 29, 2007: Message edited by: David Heffelfinger ]
 
Pamungkas Timotius
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your information, I'll try it at once
 
Pamungkas Timotius
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it works...
But I'm expecting something more specific and user-friendly

For example, if user does enter password which length is less than 6 chars, my message should display 'Password must be at least 6 characters'
but when username entered is less than 5 chars, it must displays proper message : 'Username must be at least 5 characters'

I've tried this approach in properties file


but it displays component id (e.g. newUserForm:txtUsername)

Can I display custom text instead of component's id in <h:messages> ?

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic