0

I have an application that uses Seam 2.2.2- JSF 1.1 - Hibernate Validator 3.1.0.GA. I am trying to display custom messages using hibernate validate message=() option. message=() gets displayed for other validators like @Length. But the message I set for @NotNull is not working.

Here is the code snippet.

<s:decorate id="decoration1" template="/includes/myTemplate.xhtml">         
 <ui:define name="label">userId</ui:define>
 <h:inputTextarea label="userIdFromTemplate" value="#myController.user.userId}" required="true" >
       <a4j:support event="onblur" reRender="decoration1" ajaxSingle="true"  bypassUpdates="true"/>
  </h:inputTextarea>
</s:decorate>

MyController

@Out(required = false) @Valid
Object user;

User Object Fields

 @NotNull(message="userIdFromAnno is required")
 getUserId() {
 }

When I set javax.faces.component.UIInput.REQUIRED={0} is a required field in messages.properties, I get userIdFromTemplate is a required field. Otherwise I get JSF default message Validation Error: Value is required. I never get the message "UserIdFromAnno is required".

Same code works and picks up annotation messages for @Length.

Can somebody help?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user238021
  • 1,181
  • 8
  • 30
  • 44

1 Answers1

0

Empty HTTP request parameters are by default submitted as an empty string. This is not the same as null and thus @NotNull will never be invoked. On JSF 2.0, you could use a context parameter to let JSF interpret empty submitted values as null. On JSF 1.2 you could use a custom string converter to let JSF convert empty submitted values to null. On JSF 1.1, however, by design a custom converter for strings will never be invoked.

Your best bet is using the Hibernate Validator specific @NotBlank annotation instead of @NotNull.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I tried the converter you outline din the other post. When I run in debug i see that the value is set to null and then faces UIInput's validation happens. @NotNull Hibernate Validator is not getting invoked. – user238021 Jun 20 '11 at 17:43
  • As outlined in my answer, the converter won't work on JSF 1.1. Use `@NotBlank`. – BalusC Jun 20 '11 at 17:44