-->
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: Custom Constraint Annotation: Parent Class
PostPosted: Tue Mar 08, 2011 4:11 am 
Newbie

Joined: Mon Mar 07, 2011 6:20 pm
Posts: 1
Hello,

I have a custom Constraint Annotation (@Custom) applied to a field defined in a standard class "MyBean".

public class MyBean{
@Custom
private string var;
}

In the associated

CustomValidator class implements ConstraintValidator<Custom, Object>

the

public boolean isValid(String object, ConstraintValidatorContext constraintContext)

method, is it possible to determine the base class (i.e. MyBean) of the object "var" for use in the validation?

Thanks for any help


Top
 Profile  
 
 Post subject: Re: Custom Constraint Annotation: Parent Class
PostPosted: Tue Mar 08, 2011 6:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
public boolean isValid(String object, ConstraintValidatorContext constraintContext)

If you have ConstraintValidator<Custom, Object> it really should be

Code:
public boolean isValid(Object object, ConstraintValidatorContext constraintContext)


Quote:
is it possible to determine the base class (i.e. MyBean) of the object "var" for use in the validation?


Do you really mean base class or the containing/owning class of the validated value. If it is the latter you are after the answer is no. If you need access to MyBean you would need a class level validator.

--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.