Work is in progress to release a Bean Validation 1.1-compatible release of Apache BVal. Thanks for your interest!
Matt On Thu, Oct 10, 2013 at 11:05 AM, Umesh Awasthi <[email protected]>wrote: > I believe violation.getPropertyPath().toString() will do work in all cases. > Thanks for your valuable inputs Matt. > > I have one more question regarding Bean Validation 1.1, is Apache Bval up > with 1.1 ? > > > On Thu, Oct 10, 2013 at 9:24 PM, Umesh Awasthi <[email protected]>wrote: > >> Thanks for your input Matt. >> >> I only need to check if constraint is declared on the class of the root >> bean being validated, i am not interested about complete object graph. >> >> >> I need to see more details about "violation.getPropertyPath().toString()" >> . >> >> Thanks >> Umesh >> >> >> On Thu, Oct 10, 2013 at 9:18 PM, Matt Benson <[email protected]>wrote: >> >>> I am still not sure of your terminology. If by "class level" you mean >>> the constraint in question was declared on the class of the root bean being >>> validated, then yes. Actually, no--the right test would be >>> violation.getPropertyPath().iterator().next().getName() == null. If by >>> "class level" you mean to learn whether the constraint was declared at the >>> class level anywhere in your object graph, this test is not sufficient. >>> >>> The most efficient way I know to get an EL-compatible path such as you >>> describe, at least in Apache BVal, is to invoke >>> violation.getPropertyPath().toString(). ;) >>> >>> Matt >>> >>> >>> On Thu, Oct 10, 2013 at 10:33 AM, Umesh Awasthi >>> <[email protected]>wrote: >>> >>>> Thanks Maat for your inputs,in short you mean if >>>> "violation.getPropertyPath(). >>>> iterator().hasNext()." have elements than constraints is property level >>>> else its a class level? >>>> >>>> Additionally i have one more issue to deal for nested bean properties >>>> validation, say i have one bean "User" with few properties and another bean >>>> "User Credentials" with more properties, so in order to populate data >>>> Underlying framework uses following naming mechanism for HTML input fields >>>> >>>> user.firstName >>>> user.user Credential.username etc >>>> >>>> which will be converted to getUser().setFirstName() etc by framework to >>>> fill data >>>> >>>> and in order to show these messages at UI level, i need to get >>>> information about field name being validated, one option is iterate through >>>> "ConstraintViolation.getPropertyPath().iterator()" and build field names >>>> but i am wondering if there is any other more efficient way to do this? >>>> >>>> Thanks >>>> Umesh >>>> >>>> >>>> On Thu, Oct 10, 2013 at 8:51 PM, Matt Benson <[email protected]>wrote: >>>> >>>>> Hello, >>>>> >>>>> Your sample code seems to do more work than necessary for the result >>>>> it finds. Every Node returned by the Path should be non-null, therefore >>>>> your whole test could be reduced to >>>>> violation.getPropertyPath().iterator().hasNext(). >>>>> >>>>> I'm not sure the above actually gives you exactly what it is you're >>>>> looking for. If you simply want to know whether the violated constraint >>>>> was declared as a class level constraint of the root bean, then it works. >>>>> But to use the Business/Employee model as an example, if you need to >>>>> differentiate between a constraint declared on the Employee class as >>>>> opposed to one declared on Business.manager (of type Employee), your >>>>> approach will fall short. >>>>> >>>>> It appears to me as though (violation.getLeafBean() == >>>>> violation.getInvalidValue()) should be true when the constraint was >>>>> declared on the bean class. >>>>> >>>>> Matt >>>>> >>>>> >>>>> >>>>> On Thu, Oct 10, 2013 at 4:44 AM, Umesh Awasthi <[email protected] >>>>> > wrote: >>>>> >>>>>> I need to determine type of constraint violation from >>>>>> [ConstraintViolation][1] object. >>>>>> one way is to use `ConstraintViolation#getPropertyPath()`. If >>>>>> `getName()` returns null on the `leaf` node you have a class level >>>>>> constraint, otherwise a property level constraint. >>>>>> >>>>>> >>>>>> One option is like >>>>>> >>>>>> Iterator<Node> >>>>>> violationNodes=violation.getPropertyPath().iterator(); >>>>>> Node leafNode=null; >>>>>> while (violationNodes.hasNext()){ >>>>>> leafNode=violationNodes.next(); >>>>>> } >>>>>> >>>>>> if(leafNode!=null){ >>>>>> // property constraint >>>>>> } >>>>>> else{ >>>>>> // class constraint >>>>>> } >>>>>> >>>>>> >>>>>> Is this good approach to determine or there can be other efficient or >>>>>> good approach to do this? >>>>>> >>>>>> -- >>>>>> With Regards >>>>>> Umesh Awasthi >>>>>> http://www.travellingrants.com/ >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>>> -- >>>> With Regards >>>> Umesh Awasthi >>>> http://www.travellingrants.com/ >>>> >>>> >>>> >>> >>> >> >> >> -- >> With Regards >> Umesh Awasthi >> http://www.travellingrants.com/ >> >> >> > > > > -- > With Regards > Umesh Awasthi > http://www.travellingrants.com/ > > >
