Search in sources :

Example 81 with WComponent

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

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

Example 83 with WComponent

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

the class WPhoneNumberFieldRenderer method doRender.

/**
 * Paints the given WPhoneNumberField.
 *
 * @param component the WPhoneNumberField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPhoneNumberField field = (WPhoneNumberField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = field.isReadOnly();
    xml.appendTagOpen("ui:phonenumberfield");
    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 minLength = field.getMinLength();
        int maxLength = field.getMaxLength();
        String pattern = field.getPattern();
        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("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("pattern", !Util.empty(pattern), pattern);
        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:phonenumberfield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 84 with WComponent

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

the class WRepeaterRenderer method paintRows.

/**
 * Paints the rows.
 *
 * @param repeater the repeater to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
protected void paintRows(final WRepeater repeater, final WebXmlRenderContext renderContext) {
    List<?> beanList = repeater.getBeanList();
    WComponent row = repeater.getRepeatedComponent();
    for (int i = 0; i < beanList.size(); i++) {
        Object rowData = beanList.get(i);
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = repeater.getRowContext(rowData, i);
        UIContextHolder.pushContext(rowContext);
        try {
            row.paint(renderContext);
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext)

Example 85 with WComponent

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

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