use of com.github.bordertech.wcomponents.WNumberField in project wcomponents by BorderTech.
the class AbstractCompare method getCompareValue.
/**
* Get the value to use in the compare.
* <p>
* It will return the same "value" the client would have used in its subordinate logic.
* </p>
* <p>
* The compare value will either be (i) a date formatted String for WDateFields, (ii) a BigDecimal for WNumberFields
* or (iii) a String value.
* </p>
*
* @return the value to be used for the compare.
*/
protected Object getCompareValue() {
// Date Compare (Use Date Formatted String - YYYY-MM-DD)
if (trigger instanceof WDateField) {
return value == null ? null : new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(value);
} else if (trigger instanceof WNumberField) {
// Number Compare (Use Number Object)
return value;
} else if (trigger instanceof AbstractWSelectList) {
// String Compare - List (Use the Option's Code)
final AbstractWSelectList listTrigger = (AbstractWSelectList) trigger;
final List<?> options = listTrigger.getOptions();
// No options, just return the compare value (so that a test against null works correctly)
if (options == null || options.isEmpty()) {
return value == null ? null : value.toString();
}
// Check if the value is a valid option allowing for "Legacy" matching
if (SelectListUtil.containsOptionWithMatching(options, value)) {
Object option = SelectListUtil.getOptionWithMatching(options, value);
String code = listTrigger.optionToCode(option);
return code;
}
// Return the value as a String - Treat empty the same as null
return (value == null || Util.empty(value.toString())) ? null : value.toString();
} else if (trigger instanceof RadioButtonGroup && value instanceof WRadioButton) {
// String Compare for RadioButtonGroup and value is WRadioButton (Use the button value)
// Note - This is only for backward compatibility where projects have used a radio button
// in the trigger. Projects should use the value expected, not the radio button.
// If the radio button passed into the compare is used in a repeater, then this compare will not work.
String data = ((WRadioButton) value).getValue();
// Treat empty the same as null
return Util.empty(data) ? null : data;
} else {
// Treat empty the same as null
return (value == null || Util.empty(value.toString())) ? null : value.toString();
}
}
use of com.github.bordertech.wcomponents.WNumberField in project wcomponents by BorderTech.
the class WNumberFieldRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WNumberField numberField = new WNumberField();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(numberField) instanceof WNumberFieldRenderer);
}
use of com.github.bordertech.wcomponents.WNumberField in project wcomponents by BorderTech.
the class WNumberFieldRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WNumberField numberField = new WNumberField();
MockRequest request = new MockRequest();
request.setParameter(numberField.getId(), getMaliciousContent());
numberField.serviceRequest(request);
assertSafeContent(numberField);
numberField.setToolTip(getMaliciousAttribute("ui:numberfield"));
assertSafeContent(numberField);
numberField.setAccessibleText(getMaliciousAttribute("ui:numberfield"));
assertSafeContent(numberField);
}
use of com.github.bordertech.wcomponents.WNumberField in project wcomponents by BorderTech.
the class AbstractCompare_Test method testGetCompareValueNumberField.
@Test
public void testGetCompareValueNumberField() {
WNumberField trigger = new WNumberField();
// Null Value
AbstractCompare compare = new MyCompare(trigger, null);
Assert.assertNull("NumberField Compare Value - should be null for null number", compare.getCompareValue());
// Value
BigDecimal value = BigDecimal.valueOf(5);
compare = new MyCompare(trigger, value);
Assert.assertEquals("NumberField Compare Value - should be the number value", value, compare.getCompareValue());
}
use of com.github.bordertech.wcomponents.WNumberField in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testAllConditions.
@Test
public void testAllConditions() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WNumberField();
SubordinateTrigger condTrigger2 = new WTextField();
SubordinateTarget actionTarget = new WTextField();
BigDecimal value = BigDecimal.valueOf(2);
Condition cond1 = new Equal(condTrigger, value);
Condition cond2 = new NotEqual(condTrigger, value);
Condition cond3 = new LessThan(condTrigger, value);
Condition cond4 = new LessThanOrEqual(condTrigger, value);
Condition cond5 = new GreaterThan(condTrigger, value);
Condition cond6 = new GreaterThanOrEqual(condTrigger, value);
Condition cond7 = new Match(condTrigger2, "[abc]");
// Basic Condition
Rule rule = new Rule();
rule.setCondition(new And(cond1, cond2, cond3, cond4, cond5, cond6, cond7));
rule.addActionOnTrue(new Show(actionTarget));
rule.addActionOnFalse(new Hide(actionTarget));
// Setup Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
WContainer root = new WContainer();
root.add(condTrigger);
root.add(condTrigger2);
root.add(actionTarget);
root.add(control);
setActiveContext(createUIContext());
// Validate Schema
assertSchemaMatch(root);
assertXpathNotExists("//ui:subordinate/ui:and/ui:condition[1]/@operator", root);
assertXpathEvaluatesTo("ne", "//ui:subordinate/ui:and/ui:condition[2]/@operator", root);
assertXpathEvaluatesTo("lt", "//ui:subordinate/ui:and/ui:condition[3]/@operator", root);
assertXpathEvaluatesTo("le", "//ui:subordinate/ui:and/ui:condition[4]/@operator", root);
assertXpathEvaluatesTo("gt", "//ui:subordinate/ui:and/ui:condition[5]/@operator", root);
assertXpathEvaluatesTo("ge", "//ui:subordinate/ui:and/ui:condition[6]/@operator", root);
assertXpathEvaluatesTo("rx", "//ui:subordinate/ui:and/ui:condition[7]/@operator", root);
}
Aggregations