use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WDateFieldExample method addContraintExamples.
/**
* Add constraint example.
*/
private void addContraintExamples() {
add(new WHeading(HeadingLevel.H2, "Date fields with input constraints"));
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(33);
add(layout);
/* mandatory */
WDateField constrainedDateField = new WDateField();
constrainedDateField.setMandatory(true);
layout.addField("Mandatory date field", constrainedDateField);
/* min date */
constrainedDateField = new WDateField();
constrainedDateField.setMinDate(new Date());
layout.addField("Minimum date today", constrainedDateField);
/* max date */
constrainedDateField = new WDateField();
constrainedDateField.setMaxDate(new Date());
layout.addField("Maximum date today", constrainedDateField);
/* auto complete */
constrainedDateField = new WDateField();
constrainedDateField.setBirthdayAutocomplete();
layout.addField("With autocomplete hint", constrainedDateField);
constrainedDateField = new WDateField();
constrainedDateField.setAutocompleteOff();
layout.addField("With autocomplete off", constrainedDateField);
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WLabelExample method addAntiPatternExamples.
/**
* Add examples you should never follow. DO NOT use the following as examples of what to do: these are examples of what NOT to do.
*/
private void addAntiPatternExamples() {
add(new WHeading(HeadingLevel.H2, "WLabel anti-patterns"));
add(new ExplanatoryText("These are here for testing purposes and must not be used as examples to follow.\n" + "Turn on debugging (bordertech.wcomponents.debug.enabled=true) to get much more information."));
add(new WHeading(HeadingLevel.H3, "Poor but not erroneous uses of WLabel"));
WPanel errorLayoutPanel = new WPanel();
errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
add(errorLayoutPanel);
// label not for anything should not be a WLabel
errorLayoutPanel.add(new WLabel("I am not 'for' anything"));
// WLabel for something which is not labellable
errorLayoutPanel.add(new WLabel("I am for a component which should not be labelled", errorLayoutPanel));
// If the WLabel is 'for' something that is not in the tree it becomes 'for' the WApplication. This is not necessarily a good thing!!!
WCheckBox notHere = new WCheckBox();
errorLayoutPanel.add(new WLabel("My component wasn't added", notHere));
/*
* The examples which follow MUST NEVER BE USED! They cause ERRORS.
* They are here purely for framework testing.
*/
add(new WHeading(HeadingLevel.H3, "Very bad uses of WLabel"));
errorLayoutPanel = new WPanel();
errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
add(errorLayoutPanel);
/*
* Nested WLabels: very bad
*/
errorLayoutPanel.add(new ExplanatoryText("This example shows nested WLabels. This is a contravention of the HTML specification."));
WPanel nestingErrorPanel = new WPanel();
nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, Size.LARGE, Size.MEDIUM));
errorLayoutPanel.add(nestingErrorPanel);
WTextField outerField = new WTextField();
WLabel outerLabel = new WLabel("I am an outer label", outerField);
nestingErrorPanel.add(outerLabel);
WTextField innerField = new WTextField();
WLabel innerLabel = new WLabel("Inner label", innerField);
// add the inner label to the outer label: this is the ERROR
outerLabel.add(innerLabel);
nestingErrorPanel.add(innerField);
nestingErrorPanel.add(outerField);
/*
* It is permissible to place certain simple form control components into
* a WLabel under the following conditions:
* there must be no more than one such component in the WLabel;
* the component MUST be one which outputs a simple HTML form control
* (and I am not going to tell you which they are);
* The WLabel must be 'for' the nested component or not 'for' anything.
*/
errorLayoutPanel.add(new ExplanatoryText("This example shows a WLabel with a nested simple form control WTextField but the WLabel is not " + "'for' the WTextField. This is a contravention of the HTML specification."));
WTextField notMyField = new WTextField();
notMyField.setToolTip("This field should not be in the label it is in");
WTextField myField = new WTextField();
WLabel myFieldLabel = new WLabel("I am not the label for my nested text field", myField);
nestingErrorPanel = new WPanel();
nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, Size.LARGE, Size.MEDIUM));
errorLayoutPanel.add(nestingErrorPanel);
nestingErrorPanel.add(myFieldLabel);
nestingErrorPanel.add(myField);
// adding the 'wrong' WTextField to a WLabel is what causes this error
myFieldLabel.add(notMyField);
add(new ExplanatoryText("The next field has a label explicitly set to only white space."));
WTextField emptyLabelTextField = new WTextField();
WLabel emptyLabel = new WLabel(" ", emptyLabelTextField);
add(emptyLabel);
add(emptyLabelTextField);
add(new WHeading(HeadingLevel.H2, "Unlabelled controls"));
add(new ExplanatoryText("These controls must be labelled but are not."));
WFieldLayout fieldsFlat = new WFieldLayout();
add(fieldsFlat);
fieldsFlat.addField((WLabel) null, new WTextField());
fieldsFlat.addField((WLabel) null, new WTextArea());
fieldsFlat.addField((WLabel) null, new WDateField());
fieldsFlat.addField((WLabel) null, new WCheckBox());
fieldsFlat.addField((WLabel) null, new WCheckBoxSelect(new String[] { "Apple", "Cherry", "Orange", "Pineapple" }));
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method setupTrigger.
/**
* Setup the trigger for the subordinate control.
*/
private void setupTrigger() {
String label = drpTriggerType.getSelected() + " Trigger";
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(LABEL_WIDTH);
buildControlPanel.add(layout);
switch((TriggerType) drpTriggerType.getSelected()) {
case RADIOBUTTONGROUP:
trigger = new RadioButtonGroup();
WFieldSet rbSet = new WFieldSet("Select an option");
RadioButtonGroup group = (RadioButtonGroup) trigger;
WRadioButton rb1 = group.addRadioButton("A");
WRadioButton rb2 = group.addRadioButton("B");
WRadioButton rb3 = group.addRadioButton("C");
rbSet.add(group);
rbSet.add(rb1);
rbSet.add(new WLabel("A", rb1));
rbSet.add(new WText("\u00a0"));
rbSet.add(rb2);
rbSet.add(new WLabel("B", rb2));
rbSet.add(new WText("\u00a0"));
rbSet.add(rb3);
rbSet.add(new WLabel("C", rb3));
layout.addField(label, rbSet);
return;
case CHECKBOX:
trigger = new WCheckBox();
break;
case CHECKBOXSELECT:
trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
break;
case DATEFIELD:
trigger = new WDateField();
break;
case DROPDOWN:
trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
break;
case EMAILFIELD:
trigger = new WEmailField();
break;
case MULTISELECT:
trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
break;
case MULTISELECTPAIR:
trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
break;
case NUMBERFIELD:
trigger = new WNumberField();
break;
case PARTIALDATEFIELD:
trigger = new WPartialDateField();
break;
case PASSWORDFIELD:
trigger = new WPasswordField();
break;
case PHONENUMBERFIELD:
trigger = new WPhoneNumberField();
break;
case RADIOBUTTONSELECT:
trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
break;
case SINGLESELECT:
trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
break;
case TEXTAREA:
trigger = new WTextArea();
((WTextArea) trigger).setMaxLength(1000);
break;
case TEXTFIELD:
trigger = new WTextField();
break;
default:
throw new SystemException("Trigger type not valid");
}
layout.addField(label, trigger);
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WDateFieldRenderer_Test method testRendererCorrectlyConfigured.
/**
* Test the Layout is correctly configured.
*/
@Test
public void testRendererCorrectlyConfigured() {
WDateField dateField = new WDateField();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(dateField) instanceof WDateFieldRenderer);
}
use of com.github.bordertech.wcomponents.WDateField in project wcomponents by BorderTech.
the class WDateFieldRenderer_Test method testDoPaintReadOnly.
@Test
public void testDoPaintReadOnly() throws IOException, SAXException, XpathException {
WDateField dateField = new WDateField();
dateField.setDate(TEST_DATE);
dateField.setReadOnly(true);
setActiveContext(createUIContext());
// Validate Schema
assertSchemaMatch(dateField);
assertXpathEvaluatesTo("true", "//ui:datefield/@readOnly", dateField);
assertXpathEvaluatesTo(TEST_INTERNAL_DATE_STRING, "//ui:datefield/@date", dateField);
}
Aggregations