Search in sources :

Example 1 with WMultiTextField

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

the class WMultiTextFieldRenderer method doRender.

/**
 * Paints the given WMultiTextField.
 *
 * @param component the WMultiTextField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiTextField textField = (WMultiTextField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = textField.isReadOnly();
    String[] values = textField.getTextInputs();
    xml.appendTagOpen("ui:multitextfield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", textField.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int cols = textField.getColumns();
        int minLength = textField.getMinLength();
        int maxLength = textField.getMaxLength();
        int maxInputs = textField.getMaxInputs();
        String pattern = textField.getPattern();
        xml.appendOptionalAttribute("disabled", textField.isDisabled(), "true");
        xml.appendOptionalAttribute("required", textField.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", textField.getToolTip());
        xml.appendOptionalAttribute("accessibleText", textField.getAccessibleText());
        xml.appendOptionalAttribute("size", cols > 0, cols);
        xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
        xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
        xml.appendOptionalAttribute("max", maxInputs > 0, maxInputs);
        xml.appendOptionalAttribute("pattern", !Util.empty(pattern), pattern);
        xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(textField));
        xml.appendOptionalAttribute("title", I18nUtilities.format(null, InternalMessages.DEFAULT_MULTI_FORM_COMPONENT_TIP));
    }
    xml.appendClose();
    if (values != null) {
        for (String value : values) {
            xml.appendTag("ui:value");
            xml.appendEscaped(value);
            xml.appendEndTag("ui:value");
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(textField, renderContext);
    }
    xml.appendEndTag("ui:multitextfield");
}
Also used : WMultiTextField(com.github.bordertech.wcomponents.WMultiTextField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WMultiTextField

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

the class WLabelRenderer_Test method testWhatForGroup3.

@Test
public void testWhatForGroup3() throws IOException, SAXException, XpathException {
    WMultiTextField comp = new WMultiTextField();
    WLabel label = new WLabel("label", comp);
    assertSchemaMatch(label);
    assertXpathEvaluatesTo("group", "//ui:label/@what", label);
}
Also used : WMultiTextField(com.github.bordertech.wcomponents.WMultiTextField) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 3 with WMultiTextField

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

the class WMultiTextFieldRenderer_Test method testDoPaintOptions.

@Test
public void testDoPaintOptions() throws IOException, SAXException, XpathException {
    WMultiTextField field = new WMultiTextField();
    field.setTextInputs(new String[] { "a", "b" });
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:multitextfield/@id", field);
    assertXpathNotExists("//ui:multitextfield/@disabled", field);
    assertXpathNotExists("//ui:multitextfield/@hidden", field);
    assertXpathNotExists("//ui:multitextfield/@required", field);
    assertXpathNotExists("//ui:multitextfield/@readOnly", field);
    assertXpathNotExists("//ui:multitextfield/@toolTip", field);
    assertXpathNotExists("//ui:multitextfield/@accessibleText", field);
    assertXpathNotExists("//ui:multitextfield/@size", field);
    assertXpathNotExists("//ui:multitextfield/@minLength", field);
    assertXpathNotExists("//ui:multitextfield/@maxLength", field);
    assertXpathNotExists("//ui:multitextfield/@max", field);
    assertXpathNotExists("//ui:multitextfield/@pattern", field);
    field.setDisabled(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:multitextfield/@disabled", field);
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:multitextfield/@hidden", field);
    field.setMandatory(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:multitextfield/@required", field);
    field.setToolTip("tooltip");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getToolTip(), "//ui:multitextfield/@toolTip", field);
    field.setAccessibleText("accessible");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getAccessibleText(), "//ui:multitextfield/@accessibleText", field);
    field.setColumns(40);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("40", "//ui:multitextfield/@size", field);
    field.setMinLength(45);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("45", "//ui:multitextfield/@minLength", field);
    field.setMaxLength(50);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("50", "//ui:multitextfield/@maxLength", field);
    field.setMaxInputs(10);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("10", "//ui:multitextfield/@max", field);
    field.setPattern("");
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:multitextfield/@pattern", field);
    field.setPattern("test[123]");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getPattern(), "//ui:multitextfield/@pattern", field);
    field.setPlaceholder("enter stuff here");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("enter stuff here", "//ui:multitextfield/@placeholder", field);
}
Also used : WMultiTextField(com.github.bordertech.wcomponents.WMultiTextField) Test(org.junit.Test)

Example 4 with WMultiTextField

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

the class WMultiTextFieldRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WMultiTextField wmtf = new WMultiTextField();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(wmtf) instanceof WMultiTextFieldRenderer);
}
Also used : WMultiTextField(com.github.bordertech.wcomponents.WMultiTextField) Test(org.junit.Test)

Example 5 with WMultiTextField

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

the class WMultiTextFieldRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    WMultiTextField field = new WMultiTextField();
    field.setReadOnly(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:multitextfield/@readOnly", field);
}
Also used : WMultiTextField(com.github.bordertech.wcomponents.WMultiTextField) Test(org.junit.Test)

Aggregations

WMultiTextField (com.github.bordertech.wcomponents.WMultiTextField)7 Test (org.junit.Test)6 WLabel (com.github.bordertech.wcomponents.WLabel)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1