Package javax.validation

Examples of javax.validation.ConstraintViolation


    morgan.addPlayedWith( clint );
    clint.addPlayedWith( morgan );

    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
    assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
    assertCorrectPropertyPaths(
        constraintViolations, "playedWith[0].playedWith[1].lastName", "playedWith[1].lastName"
    );
  }
View Full Code Here


    StringBuffer message = new StringBuffer();

    if (!violations.isEmpty()) {
      for (Iterator iter = violations.iterator(); iter.hasNext();) {
        ConstraintViolation violation = (ConstraintViolation) iter.next();
        message.append(field.toGenericString() + " " + violation.getMessage() + "\n");
      }

      throw new ConfigurationException(message.toString(), new ConstraintViolationException(violations));
    }
  }
View Full Code Here

    public <E> void validate(E entity, String idFieldName) {
        Validator v = validatorFactory.getValidator();

        Set<ConstraintViolation<E>> violations = v.validate(entity);
        if (violations.size() > 0) {
            ConstraintViolation   cv = getFirstContraintViolation(violations, idFieldName);
            //return first error
            throw new EntityConstraintViolationException(cv.getRootBeanClass().getSimpleName(),
                    cv.getPropertyPath().toString(),cv.getInvalidValue(),cv.getMessage());
        }
    }
View Full Code Here

        constraintsBox.setAlignment(Pos.CENTER_LEFT);
        controller.getConstraintViolations().addListener(new ListChangeListener() {
            public void onChanged(Change change) {
                constraintsBox.getChildren().clear();
                for (Object o : controller.getConstraintViolations()) {
                    ConstraintViolation constraintViolation = (ConstraintViolation) o;
                    Label errorLabel = new Label(constraintViolation.getMessage());
                    ImageView warningView = new ImageView(WARNING);
                    warningView.setFitHeight(15);
                    warningView.setPreserveRatio(true);
                    warningView.setSmooth(true);
                    errorLabel.setGraphic(warningView);
View Full Code Here

            }

            if (violations != null && !violations.isEmpty()) {
                ValidatorException toThrow;
                if (1 == violations.size()) {
                    ConstraintViolation violation = violations.iterator().next();
                    toThrow = new ValidatorException(MessageFactory.getMessage(
                          context,
                          MESSAGE_ID,
                          violation.getMessage(),
                          MessageFactory.getLabel(context, component)));
                } else {
                    Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(
                          violations.size());
                    for (ConstraintViolation violation : violations) {
                        messages.add(MessageFactory.getMessage(context,
                                                               MESSAGE_ID,
                                                               violation.getMessage(),
                                                               MessageFactory.getLabel(
                                                                     context,
                                                                     component)));
                    }
                    toThrow = new ValidatorException(messages);
View Full Code Here

TOP

Related Classes of javax.validation.ConstraintViolation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.