views:

92

answers:

1

Hey,

I have this a field:

<h:inputText id="email" value="#{user.user.email}" title="Email" validator="#{user.user.validateEmail}"/>

The validateEmail method checks if the email address's length is greater than 0, if not, it throws an exception. I thought this would work, but sadly the method is called only if you enter a value. Why?

Thanks in advance!

+4  A: 

The validator is not called if the field is empty. If you need a value, set the required attribute to true for the control.

digitaljoel
But so i can't change the default error message, unless i use Bundles / Custom validator class, right?
wheelie
Yes, you will need a custom message bundle. You won't need a custom validator in order to override the required message. If you provide a custom bundle in your faces-config.xml, then in that bundle you can set the appropriate properties ( i.e. javax.faces.component.UIInput.REQUIRED ) property to your message. I believe this may be a 1.2 feature though.
digitaljoel