Search in sources :

Example 1 with WDateField

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();
    }
}
Also used : AbstractWSelectList(com.github.bordertech.wcomponents.AbstractWSelectList) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WNumberField(com.github.bordertech.wcomponents.WNumberField) WDateField(com.github.bordertech.wcomponents.WDateField) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with WDateField

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;
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) WDateField(com.github.bordertech.wcomponents.WDateField) WTextField(com.github.bordertech.wcomponents.WTextField)

Example 3 with WDateField

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;
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) WDateField(com.github.bordertech.wcomponents.WDateField) WTextField(com.github.bordertech.wcomponents.WTextField)

Example 4 with WDateField

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");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WDateField(com.github.bordertech.wcomponents.WDateField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with WDateField

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());
}
Also used : ArrayList(java.util.ArrayList) WDateField(com.github.bordertech.wcomponents.WDateField) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Aggregations

WDateField (com.github.bordertech.wcomponents.WDateField)27 Test (org.junit.Test)11 WTextField (com.github.bordertech.wcomponents.WTextField)8 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)7 Date (java.util.Date)7 SimpleDateFormat (java.text.SimpleDateFormat)5 WDataTable (com.github.bordertech.wcomponents.WDataTable)4 WNumberField (com.github.bordertech.wcomponents.WNumberField)4 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)3 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLabel (com.github.bordertech.wcomponents.WLabel)3 WText (com.github.bordertech.wcomponents.WText)3 SystemException (com.github.bordertech.wcomponents.util.SystemException)3 ArrayList (java.util.ArrayList)3 AbstractWSelectList (com.github.bordertech.wcomponents.AbstractWSelectList)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)2 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2