Search in sources :

Example 6 with WTextField

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

the class WCheckBoxSelectExample method addExampleUsingStringArray.

/**
 * This example creates the WCheckBoxSelect from an array of Strings.
 */
private void addExampleUsingStringArray() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect created using a String array"));
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    final WCheckBoxSelect select = new WCheckBoxSelect(options);
    select.setToolTip("Animals");
    select.setMandatory(true);
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select Animals");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select.getSelected().isEmpty() ? NO_SELECTION : "The selected animals are: " + select.getSelected();
            text.setText(output);
        }
    });
    select.setDefaultSubmitButton(update);
    WLabel animalLabel = new WLabel("A selection is required", select);
    animalLabel.setHint("mandatory");
    add(animalLabel);
    add(select);
    add(update);
    add(text);
    add(new WAjaxControl(update, text));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 7 with WTextField

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

the class WFieldLayoutExample method recursiveFieldLayout.

/**
 * Create a recursive field layout.
 *
 * @param ordered true if all nested layouts are ordered.
 * @param curr recursion index
 * @param startAt the ordered offset
 * @return the recursive field layout.
 */
private WFieldLayout recursiveFieldLayout(final boolean ordered, final int curr, final int startAt) {
    WFieldLayout innerLayout = new WFieldLayout();
    innerLayout.setLabelWidth(20);
    if (curr == 0 && startAt == 0) {
        innerLayout.setMargin(new Margin(Size.LARGE, null, null, null));
    }
    innerLayout.setOrdered(ordered);
    if (ordered && startAt > 1) {
        innerLayout.setOrderedOffset(startAt);
    }
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt : 1), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 1 : 2), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 2 : 2), new WTextField());
    if (curr < 4) {
        int next = curr + 1;
        innerLayout.addField("indent level " + String.valueOf(next), recursiveFieldLayout(curr % 2 == 1, next, 0));
    }
    innerLayout.addField("Test after nest", new WTextField());
    return innerLayout;
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Margin(com.github.bordertech.wcomponents.Margin)

Example 8 with WTextField

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

the class WFieldLayoutExample method recursiveFieldLayout.

/**
 * Create a recursive field layout.
 *
 * @param curr recursion index
 * @param startAt the ordered offset
 * @return the recursive field layout.
 */
private WFieldLayout recursiveFieldLayout(final int curr, final int startAt) {
    WFieldLayout innerLayout = new WFieldLayout();
    innerLayout.setLabelWidth(20);
    if (curr == 0 && startAt == 0) {
        innerLayout.setMargin(new Margin(Size.LARGE, null, null, null));
    }
    innerLayout.setOrdered(true);
    if (startAt > 1) {
        innerLayout.setOrderedOffset(startAt);
    }
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt : 1), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 1 : 2), new WTextField());
    innerLayout.addField("Test " + String.valueOf(startAt > 1 ? startAt + 2 : 2), new WTextField());
    if (curr < 4) {
        int next = curr + 1;
        innerLayout.addField("indent level " + String.valueOf(next), recursiveFieldLayout(next, 0));
    }
    innerLayout.addField("Test after nest", new WTextField());
    return innerLayout;
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Margin(com.github.bordertech.wcomponents.Margin)

Example 9 with WTextField

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

the class WFieldSetExample method addFieldSet.

/**
 * 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 com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
    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;
}
Also used : WField(com.github.bordertech.wcomponents.WField) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WDropdown(com.github.bordertech.wcomponents.WDropdown) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField)

Example 10 with WTextField

use of com.github.bordertech.wcomponents.WTextField 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 }, 12, 6));
    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" }));
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) ColumnLayout(com.github.bordertech.wcomponents.layout.ColumnLayout) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WDateField(com.github.bordertech.wcomponents.WDateField) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Aggregations

WTextField (com.github.bordertech.wcomponents.WTextField)117 Test (org.junit.Test)90 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)21 WContainer (com.github.bordertech.wcomponents.WContainer)21 Equal (com.github.bordertech.wcomponents.subordinate.Equal)16 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Rule (com.github.bordertech.wcomponents.subordinate.Rule)15 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)15 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)14 WTextArea (com.github.bordertech.wcomponents.WTextArea)14 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)12 WDropdown (com.github.bordertech.wcomponents.WDropdown)12 WButton (com.github.bordertech.wcomponents.WButton)11 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 WHeading (com.github.bordertech.wcomponents.WHeading)10 WLabel (com.github.bordertech.wcomponents.WLabel)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)10