Search in sources :

Example 76 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WEmailFieldRenderer method doRender.

/**
 * Paints the given WEmailField.
 *
 * @param component the WEmailField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WEmailField field = (WEmailField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = field.isReadOnly();
    xml.appendTagOpen("ui:emailfield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int cols = field.getColumns();
        int maxLength = field.getMaxLength();
        WSuggestions suggestions = field.getSuggestions();
        String suggestionsId = suggestions == null ? null : suggestions.getId();
        WComponent submitControl = field.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("disabled", field.isDisabled(), "true");
        xml.appendOptionalAttribute("required", field.isMandatory(), "true");
        xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
        xml.appendOptionalAttribute("toolTip", field.getToolTip());
        xml.appendOptionalAttribute("accessibleText", field.getAccessibleText());
        xml.appendOptionalAttribute("size", cols > 0, cols);
        xml.appendOptionalAttribute("buttonId", submitControlId);
        xml.appendOptionalAttribute("list", suggestionsId);
        xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(field));
    }
    xml.appendClose();
    xml.appendEscaped(field.getText());
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
    }
    xml.appendEndTag("ui:emailfield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WEmailField(com.github.bordertech.wcomponents.WEmailField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 77 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WFieldSetRenderer method doRender.

/**
 * Paints the given WFieldSet.
 *
 * @param component the WFieldSet to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WFieldSet fieldSet = (WFieldSet) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:fieldset");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", fieldSet.isHidden(), "true");
    switch(fieldSet.getFrameType()) {
        case NO_BORDER:
            xml.appendOptionalAttribute("frame", "noborder");
            break;
        case NO_TEXT:
            xml.appendOptionalAttribute("frame", "notext");
            break;
        case NONE:
            xml.appendOptionalAttribute("frame", "none");
            break;
        case NORMAL:
        default:
            break;
    }
    xml.appendOptionalAttribute("required", fieldSet.isMandatory(), "true");
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(fieldSet, renderContext);
    // Label
    WDecoratedLabel label = fieldSet.getTitle();
    label.paint(renderContext);
    // Children
    xml.appendTag("ui:content");
    int size = fieldSet.getChildCount();
    for (int i = 0; i < size; i++) {
        WComponent child = fieldSet.getChildAt(i);
        // Skip label, as it has already been painted
        if (child != label) {
            child.paint(renderContext);
        }
    }
    xml.appendEndTag("ui:content");
    DiagnosticRenderUtil.renderDiagnostics(fieldSet, renderContext);
    xml.appendEndTag("ui:fieldset");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 78 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WLabelRenderer method doRender.

/**
 * Paints the given {@link WLabel}.
 *
 * @param component the WLabel to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WLabel label = (WLabel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:label");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("for", label.getLabelFor());
    WComponent what = label.getForComponent();
    String whatFor = null;
    if (what instanceof MultiInputComponent) {
        whatFor = "group";
    } else if (what instanceof Labelable) {
        whatFor = "input";
    }
    boolean isReadOnly = ((what instanceof Input) && ((Input) what).isReadOnly()) || (what instanceof WRadioButton && ((WRadioButton) what).isReadOnly());
    boolean isMandatory = (what instanceof Input) && ((Input) what).isMandatory();
    xml.appendOptionalAttribute("what", whatFor);
    xml.appendOptionalAttribute("readonly", isReadOnly, "true");
    xml.appendOptionalAttribute("required", isMandatory, "true");
    xml.appendOptionalAttribute("hiddencomponent", (what != null && what.isHidden()), "true");
    xml.appendOptionalAttribute("hint", label.getHint());
    xml.appendOptionalAttribute("accessKey", Util.upperCase(label.getAccessKeyAsString()));
    xml.appendOptionalAttribute("hidden", label.isHidden(), "true");
    xml.appendOptionalAttribute("toolTip", label.getToolTip());
    xml.appendOptionalAttribute("accessibleText", label.getAccessibleText());
    xml.appendClose();
    xml.append(label.getText(), label.isEncodeText());
    paintChildren(label, renderContext);
    xml.appendEndTag("ui:label");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Labelable(com.github.bordertech.wcomponents.Labelable) MultiInputComponent(com.github.bordertech.wcomponents.MultiInputComponent) Input(com.github.bordertech.wcomponents.Input) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 79 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WMultiFileWidgetRenderer method doRender.

/**
 * Paints the given WMultiFileWidget.
 *
 * @param component the WMultiFileWidget to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiFileWidget widget = (WMultiFileWidget) component;
    XmlStringBuilder xml = renderContext.getWriter();
    // Check if rendering a file upload response
    String uploadId = widget.getFileUploadRequestId();
    if (uploadId != null) {
        handleFileUploadRequest(widget, xml, uploadId);
        return;
    }
    boolean readOnly = widget.isReadOnly();
    xml.appendTagOpen(TAG_NAME);
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", widget.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        long maxFileSize = widget.getMaxFileSize();
        int maxFiles = widget.getMaxFiles();
        WComponent dropzone = widget.getDropzone();
        WImageEditor editor = widget.getEditor();
        xml.appendOptionalAttribute("disabled", widget.isDisabled(), "true");
        xml.appendOptionalAttribute("required", widget.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", widget.getToolTip());
        xml.appendOptionalAttribute("accessibleText", widget.getAccessibleText());
        xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(widget.getFileTypes()));
        xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
        xml.appendOptionalAttribute("maxFiles", maxFiles > 0, maxFiles);
        if (dropzone != null) {
            xml.appendAttribute("dropzone", dropzone.getId());
        }
        if (editor != null) {
            xml.appendAttribute("editor", editor.getId());
            if (editor.getUseCamera()) {
                xml.appendAttribute("camera", true);
            }
        }
    }
    if (widget.getColumns() != null) {
        xml.appendAttribute("cols", widget.getColumns());
    }
    if (widget.getFileAjaxAction() != null) {
        xml.appendAttribute("ajax", "true");
    }
    List<Diagnostic> diags = readOnly ? null : widget.getDiagnostics(Diagnostic.ERROR);
    if (widget.getFiles().isEmpty()) {
        if (readOnly || diags == null || diags.isEmpty()) {
            xml.appendEnd();
            return;
        }
        xml.appendClose();
    } else {
        xml.appendClose();
        // Render files
        int i = 0;
        for (FileWidgetUpload file : widget.getFiles()) {
            FileWidgetRendererUtil.renderFileElement(widget, xml, file, i++);
        }
    }
    if (!readOnly && diags != null && !diags.isEmpty()) {
        DiagnosticRenderUtil.renderDiagnostics(widget, renderContext);
    }
    xml.appendEndTag(TAG_NAME);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WImageEditor(com.github.bordertech.wcomponents.WImageEditor) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) FileWidgetUpload(com.github.bordertech.wcomponents.WMultiFileWidget.FileWidgetUpload) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 80 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WNumberFieldRenderer method doRender.

/**
 * Paints the given WNumberField.
 *
 * @param component the WNumberField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WNumberField field = (WNumberField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = field.isReadOnly();
    BigDecimal value = field.getValue();
    String userText = field.getText();
    xml.appendTagOpen("ui:numberfield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        WComponent submitControl = field.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        BigDecimal min = field.getMinValue();
        BigDecimal max = field.getMaxValue();
        BigDecimal step = field.getStep();
        int decimals = field.getDecimalPlaces();
        xml.appendOptionalAttribute("disabled", field.isDisabled(), "true");
        xml.appendOptionalAttribute("required", field.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", field.getToolTip());
        xml.appendOptionalAttribute("accessibleText", field.getAccessibleText());
        xml.appendOptionalAttribute("min", min != null, String.valueOf(min));
        xml.appendOptionalAttribute("max", max != null, String.valueOf(max));
        xml.appendOptionalAttribute("step", step != null, String.valueOf(step));
        xml.appendOptionalAttribute("decimals", decimals > 0, decimals);
        xml.appendOptionalAttribute("buttonId", submitControlId);
    }
    xml.appendClose();
    xml.appendEscaped(value == null ? userText : value.toString());
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
    }
    xml.appendEndTag("ui:numberfield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WNumberField(com.github.bordertech.wcomponents.WNumberField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BigDecimal(java.math.BigDecimal)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4