Example usage for com.vaadin.ui AbstractComponent getComponentError

List of usage examples for com.vaadin.ui AbstractComponent getComponentError

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractComponent getComponentError.

Prototype

public ErrorMessage getComponentError() 

Source Link

Document

Gets the component's error message.

Usage

From source file:com.expressui.core.view.field.FormField.java

License:Open Source License

/**
 * Asks if field dynamically has an error.
 *
 * @return true if field dynamically has an error
 *//*from   w w w  .ja va2 s . c o m*/
public boolean hasError() {
    if (hasConversionError) {
        return true;
    } else if (getField() instanceof AbstractComponent) {
        AbstractComponent abstractComponent = (AbstractComponent) getField();
        return abstractComponent.getComponentError() != null || hasIsRequiredError();
    } else {
        return false;
    }
}

From source file:com.expressui.core.view.field.FormField.java

License:Open Source License

/**
 * Add error message to this field.//from w w w .j  a v  a2s. c o  m
 *
 * @param errorMessage error message, builds Vaadin composite error message
 */
public void addError(ErrorMessage errorMessage) {
    Assert.PROGRAMMING.instanceOf(getField(), AbstractComponent.class,
            "Error message cannot be added to field that is not an AbstractComponent for property "
                    + getTypeAndPropertyId());

    AbstractComponent abstractComponent = (AbstractComponent) getField();
    ErrorMessage existingErrorMessage = abstractComponent.getComponentError();
    if (existingErrorMessage == null) {
        abstractComponent.setComponentError(errorMessage);
    } else if (existingErrorMessage instanceof CompositeErrorMessage) {
        CompositeErrorMessage existingCompositeErrorMessage = (CompositeErrorMessage) existingErrorMessage;
        Iterator<ErrorMessage> iterator = existingCompositeErrorMessage.iterator();
        Set<ErrorMessage> newErrorMessages = new LinkedHashSet<ErrorMessage>();
        while (iterator.hasNext()) {
            ErrorMessage next = iterator.next();
            newErrorMessages.add(next);
        }
        newErrorMessages.add(errorMessage);
        CompositeErrorMessage newCompositeErrorMessage = new CompositeErrorMessage(newErrorMessages);
        abstractComponent.setComponentError(newCompositeErrorMessage);
    } else {
        Set<ErrorMessage> newErrorMessages = new LinkedHashSet<ErrorMessage>();
        newErrorMessages.add(existingErrorMessage);
        newErrorMessages.add(errorMessage);
        CompositeErrorMessage newCompositeErrorMessage = new CompositeErrorMessage(newErrorMessages);
        abstractComponent.setComponentError(newCompositeErrorMessage);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractComponent.java

License:Apache License

protected boolean hasValidationError() {
    if (getComposition() instanceof AbstractComponent) {
        AbstractComponent composition = (AbstractComponent) getComposition();
        return composition.getComponentError() instanceof UserError;
    }/*  w  ww.jav  a  2  s.  c o  m*/
    return false;
}

From source file:com.purebred.core.view.field.FormField.java

License:Open Source License

/**
 * Add error message to this field.//from   w  w  w  . ja v  a 2 s . c o  m
 *
 * @param errorMessage error message, builds Vaadin composite error message
 */
public void addError(ErrorMessage errorMessage) {
    Assert.PROGRAMMING.assertTrue(getField() instanceof AbstractComponent,
            "Error message cannot be added to field that is not an AbstractComponent");

    AbstractComponent abstractComponent = (AbstractComponent) getField();
    ErrorMessage existingErrorMessage = abstractComponent.getComponentError();
    if (existingErrorMessage == null) {
        abstractComponent.setComponentError(errorMessage);
    } else if (existingErrorMessage instanceof CompositeErrorMessage) {
        CompositeErrorMessage existingCompositeErrorMessage = (CompositeErrorMessage) existingErrorMessage;
        Iterator<ErrorMessage> iterator = existingCompositeErrorMessage.iterator();
        Set<ErrorMessage> newErrorMessages = new LinkedHashSet<ErrorMessage>();
        while (iterator.hasNext()) {
            ErrorMessage next = iterator.next();
            newErrorMessages.add(next);
        }
        newErrorMessages.add(errorMessage);
        CompositeErrorMessage newCompositeErrorMessage = new CompositeErrorMessage(newErrorMessages);
        abstractComponent.setComponentError(newCompositeErrorMessage);
    } else {
        Set<ErrorMessage> newErrorMessages = new LinkedHashSet<ErrorMessage>();
        newErrorMessages.add(existingErrorMessage);
        newErrorMessages.add(errorMessage);
        CompositeErrorMessage newCompositeErrorMessage = new CompositeErrorMessage(newErrorMessages);
        abstractComponent.setComponentError(newCompositeErrorMessage);
    }
}