-->
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: Including the invalid-value in validation-messages
PostPosted: Sun Jan 24, 2010 4:37 pm 
Newbie

Joined: Sun Jan 24, 2010 4:20 pm
Posts: 13
Hi all. I'm using Oval for all my validation and I'm evaluating Hibernate Validation 4 as a possible replacement, as it's jsr-303 compliant and all. It seems Hibernate Validation 4 (or the bean-validation jsr-303 for that matter) is missing one convenient feature of Oval, namely the implicit variables {context} and {invalidValue} which may be used in error-messages.

Say I have this annotation in Oval:

@Length(min = 5, max = 10)
private String code;

The I can have an error-message like this:
net.sf.oval.constraint.Length.violated={context} is not between {min} and {max} characters long. Invalid value is {invalidValue}.

From the Oval-docs:
Quote:
There exist two default variables that can be used in the message string:

  • {context} = the validation context (e.g. a field, a method return value or a constructor/method parameter
  • {invalidValue} = the value that has been checked

I'm missing the {context} and {invalidValue} variables from Oval. Anyone know how to get the equivalent in Hibernate Validation 4?


Top
 Profile  
 
 Post subject: Re: Including the invalid-value in validation-messages
PostPosted: Mon Jan 25, 2010 10:48 am 
Hibernate Team
Hibernate Team

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

The actual validated value is not available per default during message interpolation. At least not in the JSR 303 specification. For later Hibernate Validator version we think about adding this feature. For now you can provide a custom MessageInterpolator. The MessageInterpolator interface gives you access to the invalid value so you can do your own interpolation. See also viewtopic.php?f=26&t=998338

--Hardy


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.