Package javax.validation

Examples of javax.validation.ConstraintViolation


        if (!constraintViolations.isEmpty())
        {
            final Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(constraintViolations.size());
            for (Object violation: constraintViolations)
            {
                final ConstraintViolation constraintViolation = (ConstraintViolation) violation;
                final String message = constraintViolation.getMessage();
                final Object[] args = new Object[]{ message, _MessageUtils.getLabel(context, component) };
                final FacesMessage msg = _MessageUtils.getErrorMessage(context, MESSAGE_ID, args);
                messages.add(msg);
            }
            throw new ValidatorException(messages);
View Full Code Here


        if (!constraintViolations.isEmpty())
        {
            final Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(constraintViolations.size());
            for (Object violation: constraintViolations)
            {
                final ConstraintViolation constraintViolation = (ConstraintViolation) violation;
                final String message = constraintViolation.getMessage();
                final Object[] args = new Object[]{ message, _MessageUtils.getLabel(context, component) };
                final FacesMessage msg = _MessageUtils.getErrorMessage(context, MESSAGE_ID, args);
                messages.add(msg);
            }
            throw new ValidatorException(messages);
View Full Code Here

        if (!constraintViolations.isEmpty())
        {
            Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(constraintViolations.size());
            for (Object violation: constraintViolations)
            {
                ConstraintViolation constraintViolation = (ConstraintViolation) violation;
                String message = constraintViolation.getMessage();
                Object[] args = new Object[]{ message, _MessageUtils.getLabel(context, component) };
                FacesMessage msg = _MessageUtils.getErrorMessage(context, MESSAGE_ID, args);
                messages.add(msg);
            }
            throw new ValidatorException(messages);
View Full Code Here

        if (!constraintViolations.isEmpty())
        {
            Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(constraintViolations.size());
            for (Object violation: constraintViolations)
            {
                ConstraintViolation constraintViolation = (ConstraintViolation) violation;
                String message = constraintViolation.getMessage();
                Object[] args = new Object[]{ message, _MessageUtils.getLabel(context, component) };
                FacesMessage msg = _MessageUtils.getErrorMessage(context, MESSAGE_ID, args);
                messages.add(msg);
            }
            throw new ValidatorException(messages);
View Full Code Here

        if (!constraintViolations.isEmpty())
        {
            final Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(constraintViolations.size());
            for (Object violation: constraintViolations)
            {
                final ConstraintViolation constraintViolation = (ConstraintViolation) violation;
                final String message = constraintViolation.getMessage();
                final Object[] args = new Object[]{ message, _MessageUtils.getLabel(context, component) };
                final FacesMessage msg = _MessageUtils.getErrorMessage(context, MESSAGE_ID, args);
                messages.add(msg);
            }
            throw new ValidatorException(messages);
View Full Code Here


    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertCorrectNumberOfViolations( constraintViolations, 2 );

    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getMessage(), "Everyone has a last name.", "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

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

    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertCorrectNumberOfViolations( constraintViolations, 2 );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getMessage(), "Everyone has a last name.", "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

    );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectPropertyPaths( constraintViolations, "orders[0].orderNumber" );
    assertCorrectConstraintViolationMessages( constraintViolations, "An order must have an order number." );

    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertConstraintViolation( constraintViolation, Customer.class, null, "orders[0].orderNumber" );
    assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );

    constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
    assertCorrectNumberOfViolations( constraintViolations, 0 );
  }
View Full Code Here

    author.setFirstName( "Gavin" );
    author.setLastName( "King" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "title" );

    book.setTitle( "Hibernate Persistence with JPA" );
    book.setSubtitle( "Revised Edition of Hibernate in Action" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages( constraintViolations, "size must be between 0 and 30" );
    constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "subtitle" );

    book.setSubtitle( "Revised Edition" );
    author.setCompany( "JBoss a divison of RedHat" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getMessage(), "size must be between 0 and 20" );
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "author.company" );

    author.setCompany( "JBoss" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
View Full Code Here

    author.setLastName( "King" );

    constraintViolations = validator.validate( book, Book.All.class );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages( constraintViolations, "may not be null" );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "title" );

    book.setTitle( "Hibernate Persistence with JPA" );
    book.setSubtitle( "Revised Edition of Hibernate in Action" );
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.