Search in sources :

Example 16 with WNumberField

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

the class WNumberFieldRenderer_Test method testSetAutocompleteOff.

@Test
public void testSetAutocompleteOff() throws IOException, SAXException, XpathException {
    WNumberField field = new WNumberField();
    field.setAutocompleteOff();
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(AutocompleteUtil.getOff(), "//ui:numberfield/@autocomplete", field);
}
Also used : WNumberField(com.github.bordertech.wcomponents.WNumberField) Test(org.junit.Test)

Example 17 with WNumberField

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

the class WNumberFieldRenderer_Test method testSetAutocomplete.

@Test
public void testSetAutocomplete() throws IOException, SAXException, XpathException {
    WNumberField field = new WNumberField();
    for (Numeric number : Numeric.values()) {
        field.setAutocomplete(number);
        assertSchemaMatch(field);
        assertXpathEvaluatesTo(number.getValue(), "//ui:numberfield/@autocomplete", field);
    }
}
Also used : Numeric(com.github.bordertech.wcomponents.autocomplete.type.Numeric) WNumberField(com.github.bordertech.wcomponents.WNumberField) Test(org.junit.Test)

Example 18 with WNumberField

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

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

the class GreaterThan_Test method testDoCompare.

@Test
public void testDoCompare() {
    WNumberField trigger = new WNumberField();
    // ------------------------------
    // Setup GREATER THAN - with value
    GreaterThan compare = new GreaterThan(trigger, EQ_VALUE);
    trigger.setNumber(null);
    Assert.assertFalse("Greater Than - Compare for null value should be false", compare.execute());
    trigger.setNumber(LT_VALUE);
    Assert.assertFalse("Greater Than - Compare for less value should be false", compare.execute());
    trigger.setNumber(EQ_VALUE);
    Assert.assertFalse("Greater Than - Compare for equal value should be false", compare.execute());
    trigger.setNumber(GT_VALUE);
    Assert.assertTrue("Greater Than - Compare for greater value should be true", compare.execute());
    // ------------------------------
    // Setup GREATER THAN - with null value
    compare = new GreaterThan(trigger, null);
    trigger.setNumber(null);
    Assert.assertFalse("Greater Than With Null Value - Compare for null value should be false", compare.execute());
    trigger.setNumber(EQ_VALUE);
    Assert.assertFalse("Greater Than With Null Value - Compare for value should be false", compare.execute());
}
Also used : WNumberField(com.github.bordertech.wcomponents.WNumberField) Test(org.junit.Test)

Example 20 with WNumberField

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

the class LessThanOrEqual_Test method testDoCompare.

@Test
public void testDoCompare() {
    WNumberField trigger = new WNumberField();
    // ------------------------------
    // Setup LESS THAN OR EQUAL - with value
    LessThanOrEqual compare = new LessThanOrEqual(trigger, EQ_VALUE);
    trigger.setNumber(null);
    Assert.assertFalse("Less Than Or Equal - Compare for null value should be false", compare.execute());
    trigger.setNumber(LT_VALUE);
    Assert.assertTrue("Less Than Or Equal - Compare for less value should be true", compare.execute());
    trigger.setNumber(EQ_VALUE);
    Assert.assertTrue("Less Than Or Equal - Compare for equal value should be true", compare.execute());
    trigger.setNumber(GT_VALUE);
    Assert.assertFalse("Less Than Or Equal - Compare for greater value should be false", compare.execute());
    // ------------------------------
    // Setup LESS THAN OR EQUAL - with null value
    compare = new LessThanOrEqual(trigger, null);
    trigger.setNumber(null);
    Assert.assertTrue("Less Than Or Equal With Null Value - Compare for null value should be true", compare.execute());
    trigger.setNumber(EQ_VALUE);
    Assert.assertFalse("Less Than Or Equal With Null Value - Compare for value should be false", compare.execute());
}
Also used : WNumberField(com.github.bordertech.wcomponents.WNumberField) Test(org.junit.Test)

Aggregations

WNumberField (com.github.bordertech.wcomponents.WNumberField)20 Test (org.junit.Test)16 BigDecimal (java.math.BigDecimal)5 WDateField (com.github.bordertech.wcomponents.WDateField)4 AbstractWSelectList (com.github.bordertech.wcomponents.AbstractWSelectList)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)2 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)2 WContainer (com.github.bordertech.wcomponents.WContainer)2 WRadioButton (com.github.bordertech.wcomponents.WRadioButton)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 Date (java.util.Date)2 AbstractWMultiSelectList (com.github.bordertech.wcomponents.AbstractWMultiSelectList)1 AbstractWSingleSelectList (com.github.bordertech.wcomponents.AbstractWSingleSelectList)1 Input (com.github.bordertech.wcomponents.Input)1 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)1 WButton (com.github.bordertech.wcomponents.WButton)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1