-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Validator Messages
PostPosted: Mon Feb 14, 2011 5:35 am 
Newbie

Joined: Mon Feb 14, 2011 4:52 am
Posts: 1
Hello folks,

I am using hibernate-validator 4.1.0.

I am wondering why you
1. do not use the JSF standard message keys for e.g. the required or length validator.
and
2. do not provide a mechanism to have the field name in the error message like the standard messages do.


Furthermore I have the problem that I don't get my custom messages running. I do something like this:
Code:
@Email(message="{com.company.application.validation.EmailValidator.WRONG_FORMAT}")
protected String email = null;

The message is contained within a message resource bundle called "ValidatorMessages" that I included in my faces-config like that:
Code:
<application>
  ...
  <message-bundle>com.netviewer.jsf.validation.ValidatorMessages</message-bundle>
</application>


My custom message is never used. What am I doing wrong?

Btw: Using a key like {javax.faces.component.UIInput.REQUIRED} which is a standard JSF key that i had overridden does not work as well.

Thx for any advice
Cheers
Christian


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Messages
PostPosted: Mon Feb 14, 2011 3:17 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi Christian,

I recommend that you have a closer look at the specification documents for JSR 303 (Bean Validation) and JSR 314 (JSF 2). They are well written and provide a lot of related information. Also Hibernate Validator's reference guide might be helpful for you.

To answer you questions:

1.) BV (and HV as its reference implementation) is a generic validation API which is not tied to any application layer. So using messages defined by one specific GUI framwork/API would not work. For instance you could use BV in a back-end application, where no GUI layer is around at all.
2.) Are you referring to JSF here? In this case you can have the field names in the messages by providing a message for the key "javax.faces.validator.BeanValidator.MESSAGE" in one of you JSF app's message bundles. In this message the field name can be referenced by the placeholder {1}, the actual validation message by {0}:

Code:
javax.faces.validator.BeanValidator.MESSAGE={1}: {0}

See the JSF 2.0 spec, section 3.5.6.3 for more information.

3.) As BV/HV is layer-agnostic it is not aware of framework-specific descriptors such as faces-config.xml. By default custom validation messages are retrieved from a bundle named ValidationMessages (see the HV reference guide), but if required you can also customize that by providing you own MessageInterpolator.

Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.