Search in sources :

Example 11 with WRadioButtonSelect

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

the class WRadioButtonSelectRenderer_Test method testOptGroupException.

@Test(expected = SystemException.class)
public void testOptGroupException() throws IOException, SAXException, XpathException {
    OptionGroup optionGroup = new OptionGroup("Test", Arrays.asList(new String[] { "A", "B" }));
    WRadioButtonSelect group = new WRadioButtonSelect(Arrays.asList(new Object[] { "X", optionGroup }));
    assertSchemaMatch(group);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Example 12 with WRadioButtonSelect

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

the class WRadioButtonSelectRenderer_Test method testDoPaintAllOptions.

@Test
public void testDoPaintAllOptions() throws IOException, SAXException, XpathException {
    WRadioButtonSelect group = new WRadioButtonSelect();
    // Set ALL Options
    group.setDisabled(true);
    setFlag(group, ComponentModel.HIDE_FLAG, true);
    group.setMandatory(true);
    group.setSubmitOnChange(true);
    group.setToolTip("tip");
    group.setFrameless(true);
    group.setAjaxTarget(new WPanel());
    group.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
    group.setButtonColumns(2);
    // Validate ALL Options
    assertSchemaMatch(group);
    assertXpathEvaluatesTo(group.getId(), "//ui:radiobuttonselect/@id", group);
    assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@disabled", group);
    assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@hidden", group);
    assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@required", group);
    assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@submitOnChange", group);
    assertXpathEvaluatesTo("tip", "//ui:radiobuttonselect/@toolTip", group);
    assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@frameless", group);
    assertXpathEvaluatesTo("column", "//ui:radiobuttonselect/@layout", group);
    assertXpathEvaluatesTo("2", "//ui:radiobuttonselect/@layoutColumnCount", group);
    assertXpathEvaluatesTo(group.getId(), "//ui:ajaxtrigger/@triggerId", group);
}
Also used : WPanel(com.github.bordertech.wcomponents.WPanel) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Example 13 with WRadioButtonSelect

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

the class SubordinateControlMandatoryExample method build.

/**
 * Creates the component to be added to the validation container. This is doen in a static method because the
 * component is passed into the superclass constructor.
 *
 * @return the component to be added to the validation container.
 */
private static WComponent build() {
    WContainer root = new WContainer();
    WSubordinateControl control = new WSubordinateControl();
    root.add(control);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 12, 0));
    WCheckBox checkBox = new WCheckBox();
    layout.addField("Set Mandatory", checkBox);
    WTextField text = new WTextField();
    layout.addField("Might need this field", text);
    WTextField mandatoryField = new WTextField();
    layout.addField("Another field always mandatory", mandatoryField);
    mandatoryField.setMandatory(true);
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    layout.addField("Select a state", rbSelect);
    root.add(layout);
    Rule rule = new Rule();
    rule.setCondition(new Equal(checkBox, Boolean.TRUE.toString()));
    rule.addActionOnTrue(new Mandatory(text));
    rule.addActionOnFalse(new Optional(text));
    rule.addActionOnTrue(new Mandatory(rbSelect));
    rule.addActionOnFalse(new Optional(rbSelect));
    control.addRule(rule);
    return root;
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 14 with WRadioButtonSelect

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

the class WRadioButtonSelectExample method makeSimpleExample.

/**
 * Make a simple editable example. The label for this example is used to get the example for use in the unit tests.
 */
private void makeSimpleExample() {
    add(new WHeading(HeadingLevel.H3, "Simple WRadioButtonSelect"));
    WPanel examplePanel = new WPanel();
    examplePanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.MEDIUM));
    add(examplePanel);
    /**
     * The radio button select.
     */
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Update");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            text.setText("The selected item is: " + rbSelect.getSelected());
        }
    });
    // setting the default submit button improves usability. It can be set on a WPanel or the WRadioButtonSelect directly
    examplePanel.setDefaultSubmitButton(update);
    examplePanel.add(new WLabel("Select a state or territory", rbSelect));
    examplePanel.add(rbSelect);
    examplePanel.add(text);
    examplePanel.add(update);
    add(new WAjaxControl(update, text));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 15 with WRadioButtonSelect

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

the class WRadioButtonSelectExample method addMandatorySelectExample.

/**
 * 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);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel)

Aggregations

WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)21 WHeading (com.github.bordertech.wcomponents.WHeading)10 WLabel (com.github.bordertech.wcomponents.WLabel)8 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)8 Test (org.junit.Test)8 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)7 WTextField (com.github.bordertech.wcomponents.WTextField)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)4 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)3 WButton (com.github.bordertech.wcomponents.WButton)3 WPanel (com.github.bordertech.wcomponents.WPanel)3 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WDateField (com.github.bordertech.wcomponents.WDateField)1