bval-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Umesh Awasthi <umeshawas...@gmail.com>
Subject determine between class and property level constraint
Date Thu, 10 Oct 2013 09:44:33 GMT
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/

Mime
View raw message