• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

replacing default validator message at h:messages

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
author
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
please buy this thing and then I get a fat cut of the action:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic