/** * Adds a field to the example's layout. * * @param input the input field to add. * @param labelText the label text for the field. * @param labelHint the optional label hint for the field. */ private void addFieldToLayout(final WComponent input, final String labelText, final String labelHint) { WField field = layout.addField(labelText, input); if (labelHint != null) { field.getLabel().setHint(labelHint); } } }
/** * Adds a field to the example's layout. * * @param input the input field to add. * @param labelText the label text for the field. * @param labelHint the optional label hint for the field. */ private void addFieldToLayout(final WComponent input, final String labelText, final String labelHint) { WField field = layout.addField(labelText, input); if (labelHint != null) { field.getLabel().setHint(labelHint); } } }
/** * Construct the innerLayout. */ private InnerFieldLayout() { setLabelWidth(25); dateStart.setMandatory(true); dateFinish.setMandatory(true); WField start = addField("Start", dateStart); labelStart = start.getLabel(); WField finish = addField("Finish", dateFinish); labelFinish = finish.getLabel(); }
/** * Creates a WDiagnosticComponent. */ public WDiagnosticComponent() { WFieldLayout layout = new WFieldLayout(); layout.setLabelWidth(30); layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 12, 0)); //mandatory fields inputText1.setMandatory(true); layout.addField("Unique Input 1", inputText1).getLabel().setHint("required"); inputText2.setMandatory(true); layout.addField("Unique Input 2", inputText2).getLabel().setHint( "required and must be different from unique input 1"); add(layout); }
@Test public void testAddFieldWithStringLabelCreatesWLabel() { WFieldLayout layout = new WFieldLayout(); WField field = layout.addField("Test", new WTextField()); Assert.assertEquals("Expect a WLabel", field.getLabel().getClass(), WLabel.class); }
/** * Test that ByLabel works for CheckBoxes by label id. */ @Test public void testFindByLabelId() { // Launch the web browser to the LDE WebDriver driver = getDriver(); WContainer container = (WContainer) getUi(); WFieldLayout layout = (WFieldLayout) container.getChildAt(0); WField field = (WField) layout.getChildAt(0); String labelId = field.getLabel().getId(); String componentId = field.getField().getId(); WebElement checkBox = driver.findElement(new ByLabel(labelId)); Assert.assertNotNull("Unable to find checkbox by labelId", checkBox); Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id")); }
/** * Test that ByLabel works for CheckBoxes by label text exact match. */ @Test public void testFindByLabelTextExact() { // Launch the web browser to the LDE WebDriver driver = getDriver(); WContainer container = (WContainer) getUi(); WFieldLayout layout = (WFieldLayout) container.getChildAt(0); WField field = (WField) layout.getChildAt(0); String labelText = field.getLabel().getText(); String componentId = field.getField().getId(); WebElement checkBox = driver.findElement(new ByLabel(labelText, false)); Assert.assertNotNull("Unable to find checkbox by label text", checkBox); Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id")); }
@Test public void testAddFieldWithWButtonNullLabel() { WFieldLayout layout = new WFieldLayout(); WField field = layout.addField(new WButton("Test")); Assert.assertNull(field.getLabel()); }
/** * Creates a RepeaterComponent. */ public RepeaterComponent() { fieldSet = new WFieldSet("Repeated Fields"); add(fieldSet); fieldSet.setMargin(new Margin(null, null, Size.LARGE, null)); WFieldLayout fields = new WFieldLayout(); fieldSet.add(fields); field1Text = new WTextField(); field1Text.setMinLength(2); field1Text.setMaxLength(5); WField field1 = fields.addField("Field 1", field1Text); field1Text.setMandatory(true); field1.getLabel().setHint("required"); field2Text = new WTextField(); WField field2 = fields.addField("Field 2", field2Text); field2Text.setMandatory(true); field2.getLabel().setHint("required and must only contain alphabetic characters"); field2.addValidator(new RegExFieldValidator("^[a-zA-Z]*$", "{0} must only contain alphabetic characters.")); }
/** * Creates a field layout with a couple of fields. * * @return a new field layout with content. */ private WFieldLayout createFieldLayout() { WFieldLayout fieldLayout = new WFieldLayout(); fieldLayout.addField("Field 1", new WTextField()); fieldLayout.addField("Field 2", new WTextArea()).getLabel().setHint("hint"); return fieldLayout; }
/** * Make the New user form. */ public NewUserCard() { WFieldLayout layout = new WFieldLayout(); add(layout); WTextField newUserName = new WTextField(); newUserName.setMandatory(true); newUserName.setMinLength(3); newUserName.setMaxLength(16); newUserName.setDefaultSubmitButton(submit); layout.addField("User name", newUserName).getLabel().setHint("User name must be between 3 and 16 characters."); newPassword.setMandatory(true); newPassword.setMinLength(3); newPassword.setMaxLength(16); newPassword.setDefaultSubmitButton(submit); layout.addField("Password", newPassword).getLabel().setHint("Password must be between 3 and 16 characters."); newPassword2.setMandatory(true); newPassword2.setMinLength(3); newPassword2.setMaxLength(16); newPassword2.setDefaultSubmitButton(submit); layout.addField("Repeat password", newPassword2); layout.addField((WLabel) null, submit); returnToLogInButton.setImage("/image/home.png"); returnToLogInButton.setRenderAsLink(true); }
/** * Construct the example. */ public WFieldNestedExample() { InnerFieldLayout innerLayout = new InnerFieldLayout(); WFieldSet innerFieldSet = new WFieldSet("Enter date range"); innerFieldSet.setFrameType(WFieldSet.FrameType.NONE); innerFieldSet.add(innerLayout); WFieldLayout layout = new WFieldLayout(); layout.setLabelWidth(20); WField field = layout.addField("Enter date range", innerFieldSet); WLabel layoutLabel = field.getLabel(); innerLayout.getDateStart().addValidator(new InnerFieldLayoutValidator( "{0} must be before {1} for {2}", layoutLabel, innerLayout)); WButton button = new WButton("Validate"); layout.addField((WLabel) null, button); button.setAction(new ValidatingAction(messages.getValidationErrors(), this) { @Override public void executeOnValid(final ActionEvent event) { messages.addMessage(new Message(Message.SUCCESS_MESSAGE, "Valid.")); } }); add(messages); add(new WHeading(WHeading.MAJOR, "Nested WField Example With Validation")); add(layout); }
/** * Creates a WDropdownSubmitOnChangeExample. */ public WDropdownSubmitOnChangeExample() { actMessage.setEncodeText(false); add(new ExplanatoryText("Any form control component which is not a WButton will show a visible warning in its label if its " + "submitOnChange property is set true.")); WFieldLayout flay = new WFieldLayout(); add(flay); flay.setLabelWidth(25); flay.setMargin(new Margin(null, null, Size.LARGE, null)); flay.addField("State", stateSelector).getLabel().setHint("Selecting a state will update the available regions."); flay.addField("Region", regionSelector); // Used to test control of visibility as part of submit on change. add(actMessage); actMessage.setVisible(false); stateSelector.setOptions(new String[]{null, STATE_ACT, STATE_NSW, STATE_VIC}); //This is the flag which causes accessibility problems. It may be removed completely in future versions of WComponents. //you should use AJAX instead stateSelector.setSubmitOnChange(true); stateSelector.setActionOnChange(new Action() { @Override public void execute(final ActionEvent event) { updateRegion(); regionSelector.resetData(); } }); regionSelector.setSubmitOnChange(true); }
/** * Creates a RepeaterFields. */ public RepeaterFields() { WFieldLayout fields = new WFieldLayout(); fields.setMargin(new Margin(null, null, Size.LARGE, null)); add(fields); nameText = new WTextField(); WField nameField = fields.addField("Name", nameText); nameText.setMandatory(true); nameField.getLabel().setHint("required"); repeater = new WRepeater(); repeater.setRepeatedComponent(new RepeaterComponent()); add(repeater); WPanel buttonPanel = new WPanel(WPanel.Type.FEATURE); buttonPanel.setMargin(new Margin(Size.LARGE, null, null, null)); add(buttonPanel); buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); submitBtn = new WButton("Submit", 'S'); buttonPanel.add(submitBtn); }
layout.addField("Link AccessKey", tfAccesskey).getLabel().setHint( "A single upper case letter or digit."); layout.addField("Render as button", cbRenderAsButton);
/** * Creates a SubordinateControlSimpleWMultiSelectExample. */ public SubordinateControlSimpleWMultiSelectExample() { WMultiSelect groupSelect = getGroupSelect(); groupSelect.setOptions(new String[]{OPTION_A, OPTION_B, OPTION_C}); WFieldLayout layout = new WFieldLayout(); layout.setLabelWidth(25); layout.setMargin(new Margin(null, null, Size.LARGE, null)); add(layout); layout.addField("Select one or more options", groupSelect).getLabel().setHint( "Option c requires further information"); WField extraField = layout.addField("Extra information", new WTextField()); WSubordinateControl control = new WSubordinateControl(); add(control); Rule rule = new Rule(); rule.setCondition(new Equal(groupSelect, OPTION_C)); rule.addActionOnTrue(new Show(extraField)); rule.addActionOnFalse(new Hide(extraField)); control.addRule(rule); }
/** * Creates a SubordinateControlCrtWDropdownExample. */ public SubordinateControlCrtWDropdownExample() { WFieldLayout layout = new WFieldLayout(); add(layout); layout.setLabelWidth(25); layout.setMargin(new Margin(null, null, Size.LARGE, null)); WDropdown genderDropdown = new WDropdown(new TableWithNullOption("sex")); WField field = layout.addField("Gender", genderDropdown); field.getLabel().setHint("The 'Male' option requires more information"); WTextField extraField = new WTextField(); WField xtraWField = layout.addField("Extra information", extraField); WSubordinateControl control = new WSubordinateControl(); add(control); Rule rule = new Rule(); rule.setCondition(new Equal(genderDropdown, "M")); rule.addActionOnTrue(new Show(xtraWField)); rule.addActionOnFalse(new Hide(xtraWField)); control.addRule(rule); } }
/** * When a WCheckBoxSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame, the * second doesn't */ private void addInsideAFieldLayoutExamples() { add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect inside a WFieldLayout")); add(new ExplanatoryText("When a WCheckBoxSelect is inside a WField its label is exposed in a way which appears and behaves like a regular " + "HTML label. This allows WCheckBoxSelects to be used in a layout with simple form controls (such as WTextField) and produce a " + "consistent and predicatable interface. The third example in this set uses a null label and a toolTip to hide the labelling " + "element. This can lead to user confusion and is not recommended.")); WFieldLayout layout = new WFieldLayout(); layout.setLabelWidth(25); add(layout); String[] options = new String[]{"Dog", "Cat", "Bird", "Turtle"}; WCheckBoxSelect select = new WCheckBoxSelect(options); layout.addField("Select some animals", select); String[] options2 = new String[]{"Parrot", "Galah", "Cockatoo", "Lyre"}; select = new WCheckBoxSelect(options2); layout.addField("Select some birds", select); select.setFrameless(true); // a tooltip can be used as a label stand-in even in a WField String[] options3 = new String[]{"Carrot", "Beet", "Brocolli", "Bacon - the perfect vegetable"}; select = new WCheckBoxSelect(options3); layout.addField((WLabel) null, select); select.setToolTip("Veggies"); select = new WCheckBoxSelect("australian_state"); layout.addField("Select a state", select).getLabel().setHint("This is an ajax trigger"); add(new WAjaxControl(select, layout)); }
/** * Creates a WFieldSet with content and a given FrameType. * * @param title The title to give to the WFieldSet. * @param type The decorative model of the WFieldSet * @return a WFieldSet with form control content. */ private WFieldSet addFieldSet(final String title, final WFieldSet.FrameType type) { final WFieldSet fieldset = new WFieldSet(title); fieldset.setFrameType(type); fieldset.setMargin(new Margin(null, null, Size.LARGE, null)); final WFieldLayout layout = new WFieldLayout(); fieldset.add(layout); layout.setLabelWidth(25); layout.addField("Street address", new WTextField()); final WField add2Field = layout.addField("Street address line 2", new WTextField()); add2Field.getLabel().setHidden(true); layout.addField("Suburb", new WTextField()); layout.addField("State/Territory", new WDropdown( new String[]{"", "ACT", "NSW", "NT", "QLD", "SA", "TAS", "VIC", "WA"})); //NOTE: this is an Australia-specific post code field. An Australian post code is not a number as they may contain a leading zero. final WTextField postcode = new WTextField(); postcode.setMaxLength(4); postcode.setColumns(4); postcode.setMinLength(3); layout.addField("Postcode", postcode); add(fieldset); return fieldset; }
/** * adds a WRadioButtonSelect with setMandatory(true). */ private void addMandatorySelectExample() { add(new WHeading(HeadingLevel.H3, "Mandatory WRadioButtonSelect")); add(new ExplanatoryText("When a WRadioButtonSelect is mandatory it needs a visible labelling element, otherwise many users may not know that " + "the component requires an answer.")); final WRadioButtonSelect select = new WRadioButtonSelect("australian_state"); select.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT); select.setMandatory(true); add(new WLabel("Mandatory selection", select)); add(select); add(new WHeading(HeadingLevel.H3, "Mandatory WRadioButtonSelect in a WFieldLayout")); WRadioButtonSelect select2 = new WRadioButtonSelect("australian_state"); select2.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT); select2.setMandatory(true); final WFieldLayout layout = new WFieldLayout(); layout.setLabelWidth(25); add(layout); layout.addField("Required selection", select2).getLabel().setHint("Required"); select2 = new WRadioButtonSelect("australian_state"); select2.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT); select2.setMandatory(true); select2.setToolTip("Select a state"); layout.addField((WLabel) null, select2); }