Search in sources :

Example 71 with XmlStringBuilder

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

the class WDropdownRenderer method doRender.

/**
 * Paints the given WDropdown.
 *
 * @param component the WDropdown to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDropdown dropdown = (WDropdown) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = dropdown.isReadOnly();
    String dataKey = dropdown.getListCacheKey();
    // Start tag
    xml.appendTagOpen("ui:dropdown");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", dropdown.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("data", dataKey != null, dataKey);
        xml.appendOptionalAttribute("disabled", dropdown.isDisabled(), "true");
        xml.appendOptionalAttribute("required", dropdown.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", dropdown.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", dropdown.getToolTip());
        xml.appendOptionalAttribute("accessibleText", dropdown.getAccessibleText());
        int optionWidth = dropdown.getOptionWidth();
        xml.appendOptionalAttribute("optionWidth", optionWidth > 0, optionWidth);
        xml.appendOptionalAttribute("type", getTypeAsString(dropdown.getType()));
    }
    xml.appendClose();
    // Options
    List<?> options = dropdown.getOptions();
    Object selectedOption = dropdown.getSelected();
    // For an editable dropdown (combo box), the selected option may not be in the list.
    if (dropdown.getType() == WDropdown.DropdownType.COMBO && selectedOption != null && (options == null || !options.contains(selectedOption))) {
        xml.appendTagOpen("ui:option");
        xml.appendAttribute("value", selectedOption.toString());
        xml.appendAttribute("selected", "true");
        xml.appendClose();
        xml.appendEscaped(selectedOption.toString());
        xml.appendEndTag("ui:option");
    }
    if (options != null) {
        int optionIndex = 0;
        boolean renderSelectionsOnly = readOnly || dataKey != null;
        for (Object option : options) {
            if (option instanceof OptionGroup) {
                xml.appendTagOpen("ui:optgroup");
                xml.appendAttribute("label", ((OptionGroup) option).getDesc());
                xml.appendClose();
                for (Object nestedOption : ((OptionGroup) option).getOptions()) {
                    renderOption(dropdown, nestedOption, optionIndex++, xml, selectedOption, renderSelectionsOnly);
                }
                xml.appendEndTag("ui:optgroup");
            } else {
                renderOption(dropdown, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(dropdown, renderContext);
    }
    // End tag
    xml.appendEndTag("ui:dropdown");
}
Also used : WDropdown(com.github.bordertech.wcomponents.WDropdown) OptionGroup(com.github.bordertech.wcomponents.OptionGroup) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 72 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder 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 73 with XmlStringBuilder

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

the class WFieldRenderer method doRender.

/**
 * Paints the given WField.
 *
 * @param component the WField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WField field = (WField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    int inputWidth = field.getInputWidth();
    xml.appendTagOpen("ui:field");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", field.isHidden(), "true");
    xml.appendOptionalAttribute("inputWidth", inputWidth > 0, inputWidth);
    xml.appendClose();
    // Label
    WLabel label = field.getLabel();
    if (label != null) {
        label.paint(renderContext);
    }
    // Field
    if (field.getField() != null) {
        xml.appendTag("ui:input");
        field.getField().paint(renderContext);
        if (field.getErrorIndicator() != null) {
            field.getErrorIndicator().paint(renderContext);
        }
        if (field.getWarningIndicator() != null) {
            field.getWarningIndicator().paint(renderContext);
        }
        xml.appendEndTag("ui:input");
    }
    xml.appendEndTag("ui:field");
}
Also used : WField(com.github.bordertech.wcomponents.WField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 74 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder 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 75 with XmlStringBuilder

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

the class WFileWidgetRenderer method doRender.

/**
 * Paints the given WFileWidget.
 *
 * @param component the WFileWidget to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WFileWidget fileWidget = (WFileWidget) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = fileWidget.isReadOnly();
    xml.appendTagOpen(TAG_NAME);
    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");
        xml.appendEnd();
        return;
    }
    xml.appendOptionalAttribute("disabled", fileWidget.isDisabled(), "true");
    xml.appendOptionalAttribute("required", fileWidget.isMandatory(), "true");
    xml.appendOptionalAttribute("toolTip", fileWidget.getToolTip());
    xml.appendOptionalAttribute("accessibleText", fileWidget.getAccessibleText());
    xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(fileWidget.getFileTypes()));
    long maxFileSize = fileWidget.getMaxFileSize();
    xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
    List<Diagnostic> diags = fileWidget.getDiagnostics(Diagnostic.ERROR);
    if (diags == null || diags.isEmpty()) {
        xml.appendEnd();
        return;
    }
    xml.appendClose();
    DiagnosticRenderUtil.renderDiagnostics(fileWidget, renderContext);
    xml.appendEndTag(TAG_NAME);
}
Also used : WFileWidget(com.github.bordertech.wcomponents.WFileWidget) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)102 WComponent (com.github.bordertech.wcomponents.WComponent)30 SystemException (com.github.bordertech.wcomponents.util.SystemException)17 Size (com.github.bordertech.wcomponents.Size)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)6 UIContext (com.github.bordertech.wcomponents.UIContext)5 WPanel (com.github.bordertech.wcomponents.WPanel)5 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 WButton (com.github.bordertech.wcomponents.WButton)4 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)4 WTable (com.github.bordertech.wcomponents.WTable)4 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)3 WDataTable (com.github.bordertech.wcomponents.WDataTable)3 WRepeater (com.github.bordertech.wcomponents.WRepeater)3 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2