Search in sources :

Example 16 with WDateField

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

the class WDateFieldRenderer_Test method testDoPaintBasic.

@Test
public void testDoPaintBasic() throws IOException, SAXException, XpathException {
    WDateField dateField = new WDateField();
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(dateField);
    // Check Attributes
    assertXpathEvaluatesTo(dateField.getId(), "//ui:datefield/@id", dateField);
    // Optional
    assertXpathEvaluatesTo("", "//ui:datefield", dateField);
    assertXpathNotExists("//ui:datefield[@disabled]", dateField);
    assertXpathNotExists("//ui:datefield[@hidden]", dateField);
    assertXpathNotExists("//ui:datefield[@required]", dateField);
    assertXpathNotExists("//ui:datefield[@readOnly]", dateField);
    assertXpathNotExists("//ui:datefield[@toolTip]", dateField);
    assertXpathNotExists("//ui:datefield[@accessibleText]", dateField);
    assertXpathNotExists("//ui:datefield[@buttonId]", dateField);
    assertXpathNotExists("//ui:datefield[@date]", dateField);
    assertXpathNotExists("//ui:datefield[@min]", dateField);
    assertXpathNotExists("//ui:datefield[@max]", dateField);
    assertXpathNotExists("//ui:datefield[@autocomplete]", dateField);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) Test(org.junit.Test)

Example 17 with WDateField

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

the class WDateFieldRenderer_Test method testDoPaintAllOptions.

@Test
public void testDoPaintAllOptions() throws IOException, SAXException, XpathException {
    WButton button = new WButton();
    WDateField dateField = new WDateField();
    dateField.setDate(TEST_DATE);
    dateField.setDisabled(true);
    setFlag(dateField, ComponentModel.HIDE_FLAG, true);
    dateField.setMandatory(true);
    dateField.setToolTip("TITLE");
    dateField.setAccessibleText("ALT");
    dateField.setDefaultSubmitButton(button);
    dateField.setMinDate(DateUtilities.createDate(01, 02, 2011));
    dateField.setMaxDate(DateUtilities.createDate(02, 03, 2012));
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(dateField);
    // Check Attributes
    assertXpathEvaluatesTo(dateField.getId(), "//ui:datefield/@id", dateField);
    // Optional
    assertXpathEvaluatesTo(TEST_INTERNAL_DATE_STRING, "//ui:datefield/@date", dateField);
    assertXpathEvaluatesTo("true", "//ui:datefield/@disabled", dateField);
    assertXpathEvaluatesTo("true", "//ui:datefield/@hidden", dateField);
    assertXpathEvaluatesTo("true", "//ui:datefield/@required", dateField);
    assertXpathEvaluatesTo("TITLE", "//ui:datefield/@toolTip", dateField);
    assertXpathEvaluatesTo("ALT", "//ui:datefield/@accessibleText", dateField);
    assertXpathEvaluatesTo(button.getId(), "//ui:datefield/@buttonId", dateField);
    assertXpathEvaluatesTo("2011-02-01", "//ui:datefield/@min", dateField);
    assertXpathEvaluatesTo("2012-03-02", "//ui:datefield/@max", dateField);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 18 with WDateField

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

the class WDateFieldRenderer_Test method testDoPaintAutocomplete.

@Test
public void testDoPaintAutocomplete() throws IOException, SAXException, XpathException {
    WDateField dateField = new WDateField();
    dateField.setDate(TEST_DATE);
    dateField.setBirthdayAutocomplete();
    // Validate Schema
    assertSchemaMatch(dateField);
    assertXpathEvaluatesTo("bday", "//ui:datefield/@autocomplete", dateField);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) Test(org.junit.Test)

Example 19 with WDateField

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

the class AbstractCompare method getTriggerValue.

/**
 * Get the value for the trigger.
 * <p>
 * If no request is passed in, the current value of the trigger is used.
 * </p>
 * <p>
 * It will return the same "value" the client would have used in its subordinate logic.
 * </p>
 * <p>
 * The trigger value will either be (i) a date formatted String for WDateFields, (ii) a BigDecimal for WNumberFields
 * or (iii) a List of String values for MultiSelect components or (iv) a String value.
 * </p>
 *
 * @param request the request being processed, can be null
 * @return the value to be used for the trigger
 */
protected Object getTriggerValue(final Request request) {
    // Date Compare (Use Date Formatted String - YYYY-MM-DD)
    if (trigger instanceof WDateField) {
        final WDateField input = (WDateField) trigger;
        Date date;
        if (request == null) {
            date = input.getValue();
        } else {
            date = input.getRequestValue(request);
        }
        return date == null ? null : new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(date);
    } else if (trigger instanceof WNumberField) {
        // Number Compare (Use Number Object)
        final WNumberField input = (WNumberField) trigger;
        if (request == null) {
            return input.getValue();
        } else {
            return input.getRequestValue(request);
        }
    } else if (trigger instanceof AbstractWSingleSelectList) {
        // String Compare for Single Select Lists (Use the Option's Code)
        final AbstractWSingleSelectList list = (AbstractWSingleSelectList) trigger;
        final Object selected;
        if (request == null) {
            selected = list.getValue();
        } else {
            selected = list.getRequestValue(request);
        }
        // Convert selected option to its "code" (Should always have a value)
        String code = list.optionToCode(selected);
        return code;
    } else if (trigger instanceof AbstractWMultiSelectList) {
        // String Compare for Multi Select Lists (Use the Option's Code)
        final AbstractWMultiSelectList list = (AbstractWMultiSelectList) trigger;
        final List<?> selected;
        if (request == null) {
            selected = list.getValue();
        } else {
            selected = list.getRequestValue(request);
        }
        // Empty is treated the same as null
        if (selected == null || selected.isEmpty()) {
            return null;
        }
        // Convert selected options to their "code" (Should always have a value)
        List<String> codes = new ArrayList<>(selected.size());
        for (Object select : selected) {
            String code = list.optionToCode(select);
            codes.add(code);
        }
        return codes;
    } else if (trigger instanceof Input) {
        // String Compare - Use the String Value of the Input
        final Input input = (Input) trigger;
        final Object inputValue;
        if (request == null) {
            inputValue = input.getValue();
        } else {
            inputValue = input.getRequestValue(request);
        }
        // Treat empty the same as null
        return (inputValue == null || Util.empty(inputValue.toString())) ? null : inputValue.toString();
    } else {
        throw new SystemException("Trigger is not a valid type.");
    }
}
Also used : Input(com.github.bordertech.wcomponents.Input) WNumberField(com.github.bordertech.wcomponents.WNumberField) SystemException(com.github.bordertech.wcomponents.util.SystemException) WDateField(com.github.bordertech.wcomponents.WDateField) ArrayList(java.util.ArrayList) List(java.util.List) AbstractWSelectList(com.github.bordertech.wcomponents.AbstractWSelectList) AbstractWSingleSelectList(com.github.bordertech.wcomponents.AbstractWSingleSelectList) AbstractWMultiSelectList(com.github.bordertech.wcomponents.AbstractWMultiSelectList) SimpleDateFormat(java.text.SimpleDateFormat) AbstractWMultiSelectList(com.github.bordertech.wcomponents.AbstractWMultiSelectList) Date(java.util.Date) AbstractWSingleSelectList(com.github.bordertech.wcomponents.AbstractWSingleSelectList)

Example 20 with WDateField

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

the class TreeTableHierarchyExample 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.setType(WDataTable.Type.HIERARCHIC);
    tbl.addColumn(new WTableColumn("First name", new WText()));
    tbl.addColumn(new WTableColumn("Last name", new WText()));
    tbl.addColumn(new WTableColumn("DOB", new WDateField()));
    tbl.setExpandMode(ExpandMode.CLIENT);
    tbl.setStripingType(WDataTable.StripingType.ROWS);
    TableTreeNode root = createTree();
    tbl.setDataModel(new ExampleTreeTableModel(root));
    return tbl;
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WText(com.github.bordertech.wcomponents.WText) WDataTable(com.github.bordertech.wcomponents.WDataTable) WDateField(com.github.bordertech.wcomponents.WDateField)

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