-->
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.  [ 7 posts ] 
Author Message
 Post subject: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Tue Jun 25, 2013 7:00 am 
Newbie

Joined: Tue Jun 25, 2013 6:52 am
Posts: 7
Hello,
i have a class that conatin another class object and i want to add a validation in filed inside the child object becuase just it required on this parent object :

code :
class Parent{

@NotEmpty
String field;

Child child;
}

class child{
String name;
}

how i can add validation to the child bean from parent class

Regards
Wish79


Top
 Profile  
 
 Post subject: Re: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Wed Jun 26, 2013 9:30 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Object graph validation (http://beanvalidation.org/1.1/spec/#constraintdeclarationvalidationprocess-requirements-graphvalidation) might be what you're after. Adding @Valid to your Child reference causes the child object to be validated when validating a Parent instance:

Code:
class Parent {

    @Valid
    Child child;
}


Hth,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Wed Jun 26, 2013 11:08 am 
Newbie

Joined: Tue Jun 25, 2013 6:52 am
Posts: 7
But in my Case the Child object dose not have any bean annotation because it is just i have to validate it in the parent bean , how i can do that.


Top
 Profile  
 
 Post subject: Re: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Wed Jun 26, 2013 11:13 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
I'm not following, what do you want to validate then? Do you want to check that the reference to Child is not null? If so, add @NotNull to the field. Otherwise I'd need some more details on what you actually want to achieve.

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Wed Jun 26, 2013 11:38 am 
Newbie

Joined: Tue Jun 25, 2013 6:52 am
Posts: 7
Parent Class {
Child myChild;
}

Child Class{
String name;
}

how i to check the child.name is not empty from Parent class , i do not want to add @NotEmpty on Child class , my question how do that from class

Thank
Wish79


Top
 Profile  
 
 Post subject: Re: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Thu Jun 27, 2013 3:15 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Bean Validation works by putting constraints directly to the concerned properties, types etc.

If you only want to validate @NotEmpty on the Child#name field if the Child object is referenced by a Parent object but not in other cases, you may do so using the group conversion feature from Bean Validation 1.1 or using the HV-specific default group sequence provider feature when using Bean Validation 1.0 / HV 4.x as described in this thread: https://forum.hibernate.org/viewtopic.php?f=9&t=1025406&p=2467709&hilit=convertgroup#p2467709

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: add Bean ValidationJSR 303 on filed inside child object
PostPosted: Fri Jul 19, 2013 9:29 am 
Newbie

Joined: Tue Jun 25, 2013 6:52 am
Posts: 7
but i have a problem which is always the subclass validation fire on parent class without i add @valid , Why ? i.e(as i understand it fire just if i add @valid am i true ?)

Regards
Wish79


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