Search in sources :

Example 11 with WSuggestions

use of com.github.bordertech.wcomponents.WSuggestions 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();
        String autocomplete = field.getAutocomplete();
        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("autocomplete", !Util.empty(autocomplete), autocomplete);
        xml.appendOptionalAttribute("list", suggestionsId);
        String placeholder = field.getPlaceholder();
        xml.appendOptionalAttribute("placeholder", !Util.empty(placeholder), placeholder);
    }
    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 12 with WSuggestions

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

the class WSuggestionsRenderer method doRender.

/**
 * Paints the given WSuggestions.
 *
 * @param component the WSuggestions to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WSuggestions suggestions = (WSuggestions) component;
    XmlStringBuilder xml = renderContext.getWriter();
    // Cache key for a lookup table
    String dataKey = suggestions.getListCacheKey();
    // Use AJAX if not using a cached list and have a refresh action
    boolean useAjax = dataKey == null && suggestions.getRefreshAction() != null;
    // Start tag
    xml.appendTagOpen("ui:suggestions");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("min", suggestions.getMinRefresh() > 0, suggestions.getMinRefresh());
    xml.appendOptionalAttribute("ajax", useAjax, "true");
    xml.appendOptionalAttribute("data", dataKey);
    WSuggestions.Autocomplete autocomplete = suggestions.getAutocomplete();
    if (autocomplete == WSuggestions.Autocomplete.LIST) {
        xml.appendOptionalAttribute("autocomplete", "list");
    }
    xml.appendClose();
    // Check if this is the current AJAX trigger
    boolean isTrigger = useAjax && AjaxHelper.isCurrentAjaxTrigger(suggestions);
    // Render suggestions
    if (isTrigger || (dataKey == null && !useAjax)) {
        for (String suggestion : suggestions.getSuggestions()) {
            xml.appendTagOpen("ui:suggestion");
            xml.appendAttribute("value", suggestion);
            xml.appendEnd();
        }
    }
    // End tag
    xml.appendEndTag("ui:suggestions");
}
Also used : WSuggestions(com.github.bordertech.wcomponents.WSuggestions) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 13 with WSuggestions

use of com.github.bordertech.wcomponents.WSuggestions 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);
        String placeholder = textField.getPlaceholder();
        xml.appendOptionalAttribute("placeholder", !Util.empty(placeholder), placeholder);
        String autocomplete = textField.getAutocomplete();
        xml.appendOptionalAttribute("autocomplete", !Util.empty(autocomplete), autocomplete);
    }
    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 14 with WSuggestions

use of com.github.bordertech.wcomponents.WSuggestions 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);
        String placeholder = field.getPlaceholder();
        xml.appendOptionalAttribute("placeholder", !Util.empty(placeholder), placeholder);
        String autocomplete = field.getAutocomplete();
        xml.appendOptionalAttribute("autocomplete", !Util.empty(autocomplete), autocomplete);
    }
    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)

Aggregations

WSuggestions (com.github.bordertech.wcomponents.WSuggestions)14 Test (org.junit.Test)9 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)4 WButton (com.github.bordertech.wcomponents.WButton)3 WComponent (com.github.bordertech.wcomponents.WComponent)3 WContainer (com.github.bordertech.wcomponents.WContainer)3 Action (com.github.bordertech.wcomponents.Action)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)2 WEmailField (com.github.bordertech.wcomponents.WEmailField)2 WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)1 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 UIContext (com.github.bordertech.wcomponents.UIContext)1