use of com.github.bordertech.wcomponents.WDateField 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.WDateField in project wcomponents by BorderTech.
the class TableCellWithActionExample method createTable.
/**
* Creates and configures the table to be used by the example. The table is configured with global rather than user
* data. Although this is not a realistic scenario, it will suffice for this example.
*
* @return a new configured table.
*/
private WDataTable createTable() {
WDataTable table = new WDataTable();
table.addColumn(new WTableColumn("First name", new WTextField()));
table.addColumn(new WTableColumn("Last name", new WTextField()));
table.addColumn(new WTableColumn("DOB", new WDateField()));
table.addColumn(new WTableColumn("Action", new ExampleButton()));
table.setExpandMode(ExpandMode.CLIENT);
table.setDataModel(createTableModel());
return table;
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class TreeTableExample method createTable.
/**
* Creates and configures the table to be used by the example. The table is configured with global rather than user
* data. Although this is not a realistic scenario, it will suffice for this example.
*
* @return a new configured table.
*/
private WDataTable createTable() {
WDataTable tbl = new WDataTable();
tbl.addColumn(new WTableColumn("First name", new WTextField()));
tbl.addColumn(new WTableColumn("Last name", new WTextField()));
tbl.addColumn(new WTableColumn("DOB", new WDateField()));
tbl.setExpandMode(ExpandMode.CLIENT);
TableTreeNode root = createTree();
tbl.setDataModel(new ExampleTreeTableModel(root));
return tbl;
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WDateFieldRenderer method doRender.
/**
* Paints the given WDateField.
*
* @param component the WDateField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDateField dateField = (WDateField) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = dateField.isReadOnly();
Date date = dateField.getDate();
xml.appendTagOpen("ui:datefield");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", dateField.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("disabled", dateField.isDisabled(), "true");
xml.appendOptionalAttribute("required", dateField.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", dateField.getToolTip());
xml.appendOptionalAttribute("accessibleText", dateField.getAccessibleText());
WComponent submitControl = dateField.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
xml.appendOptionalAttribute("buttonId", submitControlId);
Date minDate = dateField.getMinDate();
Date maxDate = dateField.getMaxDate();
if (minDate != null) {
xml.appendAttribute("min", new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(minDate));
}
if (maxDate != null) {
xml.appendAttribute("max", new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(maxDate));
}
String autocomplete = dateField.getAutocomplete();
xml.appendOptionalAttribute("autocomplete", !Util.empty(autocomplete), autocomplete);
}
if (date != null) {
xml.appendAttribute("date", new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date));
}
xml.appendClose();
if (date == null) {
xml.appendEscaped(dateField.getText());
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(dateField, renderContext);
}
xml.appendEndTag("ui:datefield");
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class DateFieldPivotValidator_Test method testVariablePivot.
@Test
public void testVariablePivot() {
WDateField variableField = new WDateField();
variableField.setDate(DateUtilities.createDate(31, 1, 2000));
DateFieldPivotValidator validator = new DateFieldPivotValidator(DateFieldPivotValidator.EQUAL, variableField);
WDateField dateField = new WDateField();
dateField.addValidator(validator);
List<Diagnostic> diags = new ArrayList<>();
dateField.setDate(DateUtilities.createDate(31, 1, 2000));
dateField.validate(diags);
Assert.assertTrue("Should not have any validation errors", diags.isEmpty());
dateField.setDate(DateUtilities.createDate(1, 2, 2000));
dateField.validate(diags);
Assert.assertEquals("Should have one validation error", 1, diags.size());
}
Aggregations