Seam Hibernate Validator displaying JSF messages
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:dec开发者_运维技巧orate>
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?
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:
- h:inputText which is bound to String property is submitting empty string instead of null
- Is there a converter for String?
精彩评论