File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes @NotNull: how to configure validation message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "@NotNull: how to configure validation message" Watch "@NotNull: how to configure validation message" New topic

@NotNull: how to configure validation message

Rogerio Kioshi
Ranch Hand

Joined: Apr 12, 2005
Posts: 690

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

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.

Dan Allen
Ranch Hand

Joined: Mar 05, 2003
Posts: 164
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:

Dan Allen | | Author of Seam in Action -
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

If you don't want to modify property file
in h:inputText just say requiredMessage="First Name Required"
I agree. Here's the link:
subject: @NotNull: how to configure validation message
It's not a secret anymore!