-->
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: [Validator 4] Getting the name of the failing property
PostPosted: Wed Nov 18, 2009 5:55 am 
Newbie

Joined: Wed Nov 18, 2009 5:45 am
Posts: 3
Hi all,

I'm busy working with Hibernate Validation (4.0.2.GA), and I have a small question about the error messages. Currently, I have a class like this:
Code:
class Company {
   @NotEmpty
   private String firstName;

   // .. the rest here


I validate this using the following code:
Code:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
return validator.validate(bean);


And I use this in my Wicket code to get the error message:
Code:
Set<ConstraintViolation<Company>> constraintViolations = WicketApplication.validate(company);
for (ConstraintViolation constraintViolation : constraintViolations) {
    error(constraintViolation.getMessage());
}


However, the output in my UI is something like this:
may not be empty

My question is therefor: how do I figure out what is empty? I'd rather not use the message property on the annotation, since I have to annotate around a 100 properties, and I wouldn't like to specify a 100 messages. I also cannot imagine this would be the way to go, but I haven't found the correct way yet, so if someone could help me out on this, that would be most appreciated!

Thanks,

Erik


Top
 Profile  
 
 Post subject: Re: [Validator 4] Getting the name of the failing property
PostPosted: Fri Nov 20, 2009 1:07 am 
Newbie

Joined: Mon Apr 06, 2009 9:55 pm
Posts: 12
Hi Erik,

I used this, this will display className.propertyName. You can also play with the propertyPath and display whatever you want.

constraintViolation.getRootBeanClass().getSimpleName() + "." + constraintViolation.getPropertyPath() + ": " + constraintViolation.getMessage()

Hope it helps,
Anton

bodiam wrote:
Hi all,

I'm busy working with Hibernate Validation (4.0.2.GA), and I have a small question about the error messages. Currently, I have a class like this:
Code:
class Company {
   @NotEmpty
   private String firstName;

   // .. the rest here


I validate this using the following code:
Code:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
return validator.validate(bean);


And I use this in my Wicket code to get the error message:
Code:
Set<ConstraintViolation<Company>> constraintViolations = WicketApplication.validate(company);
for (ConstraintViolation constraintViolation : constraintViolations) {
    error(constraintViolation.getMessage());
}


However, the output in my UI is something like this:
may not be empty

My question is therefor: how do I figure out what is empty? I'd rather not use the message property on the annotation, since I have to annotate around a 100 properties, and I wouldn't like to specify a 100 messages. I also cannot imagine this would be the way to go, but I haven't found the correct way yet, so if someone could help me out on this, that would be most appreciated!

Thanks,

Erik


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.