-->
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: Dynamic error messages
PostPosted: Tue Feb 26, 2013 9:03 am 
Newbie

Joined: Tue Jul 05, 2011 7:28 am
Posts: 10
Hi all,

Apologies if this has been answered before but a quick search didn't resolve my issue.

My questions is: If you take the CheckCaseValidator example in Chapter 3 of the Hibernate Validator 4.2 documentation, is it possible to display the actual string being validated in the error message? I can see from section 3.1.3 that is it possible to dynamically display a constraint in the error message but what about the object being validated?

I am using Hibernate Validator 4.2.0.Final and Spring 3.0.5.Release's LocalValidatorFactoryBean to do the bootstrapping.

Thanks,
Mark


Top
 Profile  
 
 Post subject: Re: Dynamic error messages
PostPosted: Tue Feb 26, 2013 3:35 pm 
Hibernate Team
Hibernate Team

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

You can use Hibernate Validator's ValueFormatterMessageInterpolator:

Code:
Configuration<?> configuration = Validation.byDefaultProvider().configure();
ValidatorFactory factory = configuration
    .messageInterpolator(new ValueFormatterMessageInterpolator(configuration.getDefaultMessageInterpolator()))
    .buildValidatorFactory();

Validator validator = factory.getValidator();


This interpolator allows to displa the validated value within messages using the expression ${validatedValue}. You can learn more in the reference guide:

http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html/validator-bootstrapping.html#section-message-interpolator

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Dynamic error messages
PostPosted: Thu Feb 28, 2013 9:57 am 
Newbie

Joined: Tue Jul 05, 2011 7:28 am
Posts: 10
Thanks Gunnar for your reply, this is exactly what I was looking for.


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.