Search in sources :

Example 1 with AbstractWFieldIndicator

use of com.github.bordertech.wcomponents.validation.AbstractWFieldIndicator in project wcomponents by BorderTech.

the class AbstractWFieldIndicatorRenderer method doRender.

/**
 * Paints the given AbstractWFieldIndicator.
 *
 * @param component the WFieldErrorIndicator to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    AbstractWFieldIndicator fieldIndicator = (AbstractWFieldIndicator) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WComponent validationTarget = fieldIndicator.getTargetComponent();
    // Diagnosables takes care of thieir own  messaging.
    if (validationTarget == null || (validationTarget instanceof Diagnosable && !(validationTarget instanceof Input))) {
        return;
    }
    if (validationTarget instanceof Input && !((Input) validationTarget).isReadOnly()) {
        return;
    }
    List<Diagnostic> diags = fieldIndicator.getDiagnostics();
    if (diags != null && !diags.isEmpty()) {
        xml.appendTagOpen("ui:fieldindicator");
        xml.appendAttribute("id", component.getId());
        xml.appendOptionalAttribute("track", component.isTracking(), "true");
        switch(fieldIndicator.getFieldIndicatorType()) {
            case INFO:
                xml.appendAttribute("type", "info");
                break;
            case WARN:
                xml.appendAttribute("type", "warn");
                break;
            case ERROR:
                xml.appendAttribute("type", "error");
                break;
            default:
                throw new SystemException("Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator.getFieldIndicatorType());
        }
        xml.appendAttribute("for", fieldIndicator.getRelatedFieldId());
        xml.appendClose();
        for (Diagnostic diag : diags) {
            xml.appendTag("ui:message");
            xml.appendEscaped(diag.getDescription());
            xml.appendEndTag("ui:message");
        }
        xml.appendEndTag("ui:fieldindicator");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AbstractWFieldIndicator(com.github.bordertech.wcomponents.validation.AbstractWFieldIndicator) Input(com.github.bordertech.wcomponents.Input) SystemException(com.github.bordertech.wcomponents.util.SystemException) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Diagnosable(com.github.bordertech.wcomponents.Diagnosable)

Aggregations

Diagnosable (com.github.bordertech.wcomponents.Diagnosable)1 Input (com.github.bordertech.wcomponents.Input)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 AbstractWFieldIndicator (com.github.bordertech.wcomponents.validation.AbstractWFieldIndicator)1 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)1