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);
}
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);
}
}
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");
}
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());
}
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());
}
Aggregations