-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem getting InvalidContraint for objects in collections
PostPosted: Sat May 03, 2008 6:48 am 
Newbie

Joined: Sat May 03, 2008 6:23 am
Posts: 1
I want to make a comment on the jsr-303 specification. In particular the specification of the InvalidContraint (4.2).

I think there is a problem to "rebuild the context of the failure" with InvalidContraint, in case of an object graph validation with validation of collection valued properties ( see 3.1.3). I don't see a way to retrieve the InvalidContraints for a object which is contained in a Collection.

For example if you have an rootObject Order which has a validated set of OrderItems.
In a UI you have can edit Order with OrderItems. When saving a invalid orderitem the errors of the OrderItems should be displayed. I don't know how retrieve the InvalidContraint for an OrderItem with the propertypath.

I suggest to add also reference to the validated "leaf object" , so I can retrieve the InvalidContraints for every object in a graph( even in case if they are contained in a collection). In most UI frameworks you can get a reference to the object which you are presenting (in this case an OrderItem), so getting the invalidcontraint for that object is no problem anymore if the invalidconstaint has a reference to the validated object.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 17, 2008 8:23 am 
Newbie

Joined: Sun Aug 17, 2008 8:19 am
Posts: 1
Agree, I think this reference to the validated "leaf object" should be very useful.

_________________
sqldbx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 4:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thanks, we will consider it.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: The object failing to pass the constraint
PostPosted: Thu Aug 21, 2008 4:08 am 
Newbie

Joined: Thu Apr 03, 2008 4:27 am
Posts: 10
When a bean-level constraint fails, this is the object that you get when calling javax.validation.InvalidConstraint#getValue()

When a property-level constraint fails, the JSR303 API currently does not give you access to the (child) object to which the propertyPath leads.

In the reference implementation (http://code.google.com/p/agimatec-validation/), you can access it with some extensions:
1. Create a subclass of com.agimatec.utility.validation.jsr303.InvalidConstraintImpl and add a property to hold the object

2. create a subclass of com.agimatec.utility.validation.jsr303.ConstraintValidationListener.
Method addError() gets a ValidationContext. The ValidationContext has a method getBean(), which is the object you need. Put it into the subclass of InvalidConstraintImpl

2. Subclass com.agimatec.utility.validation.jsr303.ClassValidator and overwrite method createContext(). Instanciate your subclass of ConstraintValidationListener there.

------------------
alternatively you can use BeanValidator instead of ClassValidator. Validation returns com.agimatec.utility.validation.ValidationResults instead of a Set of InvalidContraints. The API ValidationResults offers errors-by-reason and errors-by-owner. Error instances hold the object, the reason and the propertyName.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.