-->
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.  [ 3 posts ] 
Author Message
 Post subject: Add bean properties to the validation message
PostPosted: Tue Oct 20, 2009 12:23 pm 
Beginner
Beginner

Joined: Mon Dec 26, 2005 3:29 pm
Posts: 23
Hi. is it possible to add bean properties to the valdiation message? So if I have a bean that looks like this:

Code:
private int id;

@Min(5)
private int number;


Can my message indicate the id property of the bean? I would like to do something like:

Code:
constraint.Min=Value must be {integer} for item {bean.id}


Thank you.


Top
 Profile  
 
 Post subject: Re: Add bean properties to the validation message
PostPosted: Tue Oct 20, 2009 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

per default only the annotation parameters are interpolated.

There is the possbiltiy via implementing a custom message interpolator, however I don't think it is a good idea. It would only work for class level constraints where you get passed the whole entity via MessageInterpolator.Context in MessageInterpolator. interpolate(messageTemplate, MessageInterpolator.Context context) and you would need to implement some sort of EL engine which would resolve the message parameters like bean.id

--Hardy


Top
 Profile  
 
 Post subject: Re: Add bean properties to the validation message
PostPosted: Wed Oct 21, 2009 9:54 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 3:29 pm
Posts: 23
Hi Hardy.

Thanks for the reply. Yes, that's what I ended up doing. We have our own little bean expression interpreter (much like Apache's BeanUtils). Although OGNL or mvel would also work with this approach. Again, thanks for the reply and keep up the great work. Hibernate Validator is a great product.

Isaac


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.