Search in sources :

Example 81 with XmlStringBuilder

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

the class WMultiSelectRenderer method doRender.

/**
 * Paints the given WMultiSelect.
 *
 * @param component the WMultiSelect to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiSelect listBox = (WMultiSelect) component;
    XmlStringBuilder xml = renderContext.getWriter();
    String dataKey = listBox.getListCacheKey();
    boolean readOnly = listBox.isReadOnly();
    int rows = listBox.getRows();
    int min = listBox.getMinSelect();
    int max = listBox.getMaxSelect();
    xml.appendTagOpen("ui:listbox");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", listBox.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("data", dataKey != null && !readOnly, dataKey);
        xml.appendOptionalAttribute("disabled", listBox.isDisabled(), "true");
        xml.appendOptionalAttribute("required", listBox.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", listBox.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", component.getToolTip());
        xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
        xml.appendOptionalAttribute("rows", rows >= 2, rows);
        xml.appendOptionalAttribute("min", min > 0, min);
        xml.appendOptionalAttribute("max", max > 0, max);
    }
    xml.appendClose();
    // Options
    List<?> options = listBox.getOptions();
    boolean renderSelectionsOnly = readOnly || dataKey != null;
    if (options != null) {
        int optionIndex = 0;
        List<?> selections = listBox.getSelected();
        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(listBox, nestedOption, optionIndex++, xml, selections, renderSelectionsOnly);
                }
                xml.appendEndTag("ui:optgroup");
            } else {
                renderOption(listBox, option, optionIndex++, xml, selections, renderSelectionsOnly);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(listBox, renderContext);
    }
    xml.appendEndTag("ui:listbox");
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect)

Example 82 with XmlStringBuilder

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

Example 83 with XmlStringBuilder

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

the class WPanelRenderer method doRender.

/**
 * Paints the given container.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WButton submitButton = panel.getDefaultSubmitButton();
    String submitId = submitButton == null ? null : submitButton.getId();
    String titleText = panel.getTitleText();
    boolean renderChildren = isRenderContent(panel);
    xml.appendTagOpen("ui:panel");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    if (PanelMode.LAZY.equals(panel.getMode())) {
        xml.appendOptionalAttribute("hidden", !renderChildren, "true");
    } else {
        xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    }
    xml.appendOptionalAttribute("buttonId", submitId);
    xml.appendOptionalAttribute("title", titleText);
    xml.appendOptionalAttribute("accessKey", Util.upperCase(panel.getAccessKeyAsString()));
    xml.appendOptionalAttribute("type", getPanelType(panel));
    xml.appendOptionalAttribute("mode", getPanelMode(panel));
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(panel, renderContext);
    if (renderChildren) {
        renderChildren(panel, renderContext);
    } else {
        // Content will be loaded via AJAX
        xml.append("<ui:content/>");
    }
    xml.appendEndTag("ui:panel");
}
Also used : WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Example 84 with XmlStringBuilder

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

the class WPartialDateFieldRenderer method doRender.

/**
 * Paints the given WPartialDateField.
 *
 * @param component the WPartialDateField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPartialDateField dateField = (WPartialDateField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = dateField.isReadOnly();
    String date = formatDate(dateField);
    xml.appendTagOpen("ui:datefield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", dateField.isHidden(), "true");
    xml.appendOptionalAttribute("date", date);
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendAttribute("allowPartial", "true");
        xml.appendOptionalAttribute("disabled", dateField.isDisabled(), "true");
        xml.appendOptionalAttribute("required", dateField.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", dateField.getToolTip());
        xml.appendOptionalAttribute("accessibleText", dateField.getAccessibleText());
        WComponent submitControl = dateField.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("buttonId", submitControlId);
    }
    xml.appendClose();
    if (date == null) {
        xml.appendEscaped(dateField.getText());
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(dateField, renderContext);
    }
    xml.appendEndTag("ui:datefield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField)

Example 85 with XmlStringBuilder

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

the class WPasswordFieldRenderer method doRender.

/**
 * Paints the given WPasswordField.
 *
 * @param component the WPasswordField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPasswordField field = (WPasswordField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = field.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;
    }
    int cols = field.getColumns();
    int minLength = field.getMinLength();
    int maxLength = field.getMaxLength();
    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("minLength", minLength > 0, minLength);
    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("placeholder", HtmlRenderUtil.getEffectivePlaceholder(field));
    List<Diagnostic> diags = field.getDiagnostics(Diagnostic.ERROR);
    if (diags == null || diags.isEmpty()) {
        xml.appendEnd();
        return;
    }
    xml.appendClose();
    DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
    xml.appendEndTag(TAG_NAME);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WPasswordField(com.github.bordertech.wcomponents.WPasswordField) 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