• 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

@NotNull: how to configure validation message

 
Ranch Hand
Posts: 701
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm studying a Seam example application from Seam reference guide:

http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.3/doc/seam/Seam_Reference_Guide/html/Seam_Reference_Guide-Seam_Tutorial-Your_first_Seam_application_the_registration_example.html

When I submit the form, and the fields are not filled out, the following messages are shown:
"j_id2:j_id6: Validation Error: Value is required.
j_id2:j_id8: Validation Error: Value is required.
j_id2:j_id10: Validation Error: Value is required. "

How do I configure the message of each field? I wanted to show something like "It is necessary to input the user name".

The Entity class has the following method:


By the way, the validation message when the user name is not between 5 and 15 characters is working fine.
 
Author
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate Validator does not enforce the @NotNull annotation. That is taken care of by JSF. The best way to ensure that you get per-field validation messages is to use the <s ecorate> tag along with the layout/edit.xhtml template provided with seam-gen:



Right now, you are probably displaying them at the top of the page using <h:messages/>. Change that to <h:messages globalOnly="true"/>.

To customize JSF messages, you enter the keys in the messages*.properties files. Again, if you create a seam-gen project, you will see the keys that are in these files. Here are the two keys you want:

 
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't want to modify property file
in h:inputText just say requiredMessage="First Name Required"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic