Search in sources :

Example 96 with XmlStringBuilder

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

the class WTabRenderer method doRender.

/**
 * Paints the given WTab.
 *
 * @param component the WTab to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTab tab = (WTab) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:tab");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("open", tab.isOpen(), "true");
    xml.appendOptionalAttribute("disabled", tab.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", tab.isHidden(), "true");
    xml.appendOptionalAttribute("toolTip", tab.getToolTip());
    switch(tab.getMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case LAZY:
            xml.appendAttribute("mode", "lazy");
            break;
        case EAGER:
            xml.appendAttribute("mode", "eager");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case SERVER:
            xml.appendAttribute("mode", "server");
            break;
        default:
            throw new SystemException("Unknown tab mode: " + tab.getMode());
    }
    if (tab.getAccessKey() != 0) {
        xml.appendAttribute("accessKey", String.valueOf(Character.toUpperCase(tab.getAccessKey())));
    }
    xml.appendClose();
    // Paint label
    tab.getTabLabel().paint(renderContext);
    // Paint content
    WComponent content = tab.getContent();
    xml.appendTagOpen("ui:tabcontent");
    xml.appendAttribute("id", tab.getId() + "-content");
    xml.appendClose();
    // Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
    if (content != null && (TabMode.EAGER != tab.getMode() || AjaxHelper.isCurrentAjaxTrigger(tab))) {
        // Visibility of content set in prepare paint
        content.paint(renderContext);
    }
    xml.appendEndTag("ui:tabcontent");
    xml.appendEndTag("ui:tab");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) WTab(com.github.bordertech.wcomponents.WTab) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 97 with XmlStringBuilder

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

the class WTableRenderer method paintRows.

/**
 * Paints the rows of the table.
 *
 * @param table the table to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
private void paintRows(final WTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    TableModel model = table.getTableModel();
    xml.appendTagOpen("ui:tbody");
    xml.appendAttribute("id", table.getId() + ".body");
    xml.appendClose();
    if (model.getRowCount() == 0) {
        xml.appendTag("ui:nodata");
        xml.appendEscaped(table.getNoDataMessage());
        xml.appendEndTag("ui:nodata");
    } else {
        // If has at least one visible col, paint the rows.
        final int columnCount = table.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            if (table.getColumn(i).isVisible()) {
                doPaintRows(table, renderContext);
                break;
            }
        }
    }
    xml.appendEndTag("ui:tbody");
}
Also used : XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 98 with XmlStringBuilder

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

the class WTextAreaRenderer method doRender.

/**
 * Paints the given WTextArea.
 *
 * @param component the WTextArea to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTextArea textArea = (WTextArea) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = textArea.isReadOnly();
    xml.appendTagOpen("ui:textarea");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", textArea.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int cols = textArea.getColumns();
        int rows = textArea.getRows();
        int minLength = textArea.getMinLength();
        int maxLength = textArea.getMaxLength();
        WComponent submitControl = textArea.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("disabled", textArea.isDisabled(), "true");
        xml.appendOptionalAttribute("required", textArea.isMandatory(), "true");
        xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
        xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
        xml.appendOptionalAttribute("toolTip", textArea.getToolTip());
        xml.appendOptionalAttribute("accessibleText", textArea.getAccessibleText());
        xml.appendOptionalAttribute("rows", rows > 0, rows);
        xml.appendOptionalAttribute("cols", cols > 0, cols);
        xml.appendOptionalAttribute("buttonId", submitControlId);
        xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(textArea));
    }
    xml.appendClose();
    if (textArea.isRichTextArea()) {
        /*
			 * This is a nested element instead of an attribute to cater for future enhancements
			 * such as turning rich text features on or off, or specifying JSON config either as
			 * a URL attribute or a nested CDATA section.
			 */
        xml.append("<ui:rtf />");
    }
    String textString = textArea.getText();
    if (textString != null) {
        if (textArea.isReadOnly() && textArea.isRichTextArea()) {
            // read only we want to output unescaped, but it must still be XML valid.
            xml.write(HtmlToXMLUtil.unescapeToXML(textString));
        } else {
            xml.appendEscaped(textString);
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(textArea, renderContext);
    }
    xml.appendEndTag("ui:textarea");
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WComponent(com.github.bordertech.wcomponents.WComponent) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 99 with XmlStringBuilder

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

the class WTextFieldRenderer method doRender.

/**
 * Paints the given WTextField.
 *
 * @param component the WTextField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTextField textField = (WTextField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = textField.isReadOnly();
    xml.appendTagOpen("ui:textfield");
    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 = textField.getColumns();
        int minLength = textField.getMinLength();
        int maxLength = textField.getMaxLength();
        String pattern = textField.getPattern();
        WSuggestions suggestions = textField.getSuggestions();
        String suggestionsId = suggestions == null ? null : suggestions.getId();
        WComponent submitControl = textField.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("disabled", textField.isDisabled(), "true");
        xml.appendOptionalAttribute("required", textField.isMandatory(), "true");
        xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
        xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
        xml.appendOptionalAttribute("toolTip", textField.getToolTip());
        xml.appendOptionalAttribute("accessibleText", textField.getAccessibleText());
        xml.appendOptionalAttribute("size", cols > 0, cols);
        xml.appendOptionalAttribute("buttonId", submitControlId);
        xml.appendOptionalAttribute("pattern", !Util.empty(pattern), pattern);
        xml.appendOptionalAttribute("list", suggestionsId);
        xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(textField));
    }
    xml.appendClose();
    xml.appendEscaped(textField.getText());
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(textField, renderContext);
    }
    xml.appendEndTag("ui:textfield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WTextField(com.github.bordertech.wcomponents.WTextField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 100 with XmlStringBuilder

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

the class WTextRenderer method doRender.

/**
 * Paints the given WText.
 *
 * @param component the WText to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WText text = (WText) component;
    XmlStringBuilder xml = renderContext.getWriter();
    String textString = text.getText();
    if (textString != null) {
        if (text.isEncodeText()) {
            xml.print(WebUtilities.encode(textString));
        } else {
            // If we are outputting unencoded content it must be XML valid.
            xml.print(HtmlToXMLUtil.unescapeToXML(textString));
        }
    }
}
Also used : WText(com.github.bordertech.wcomponents.WText) 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