Search in sources :

Example 11 with WAjaxControl

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

the class WRadioButtonSelectExample method addInsideAFieldLayoutExample.

/**
 * When a WRadioButtonSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame,
 * the second doesn't
 */
private void addInsideAFieldLayoutExample() {
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect inside a WFieldLayout"));
    add(new ExplanatoryText("When a WRadioButtonSelect is inside a WField its label is exposed in a way which appears and behaves like a regular HTML label." + " This allows WRadioButtonSelects to be used in a layout with simple form controls (such as WTextField) and produce a consistent" + " and predicatable interface.\n" + "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."));
    // Note: the wrapper WPanel here is to work around a bug in validation. See https://github.com/BorderTech/wcomponents/issues/1370
    final WPanel wrapper = new WPanel();
    add(wrapper);
    final WMessages messages = new WMessages();
    wrapper.add(messages);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    wrapper.add(layout);
    WButton resetThisBit = new WButton("Reset this bit");
    resetThisBit.setCancel(true);
    resetThisBit.setAjaxTarget(wrapper);
    resetThisBit.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            wrapper.reset();
        }
    });
    layout.addField(resetThisBit);
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    WRadioButtonSelect select = new WRadioButtonSelect(options);
    layout.addField("Select an animal", select);
    String[] options2 = new String[] { "Parrot", "Galah", "Cockatoo", "Lyre" };
    select = new WRadioButtonSelect(options2);
    select.setMandatory(true);
    layout.addField("You must select a bird", 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 WRadioButtonSelect(options3);
    // if you absolutely do not want a WLabel in a WField then it has to be added using null cast to a WLabel.
    layout.addField((WLabel) null, select);
    select.setToolTip("Veggies");
    WButton btnValidate = new WButton("validate");
    btnValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // do nothing
        }
    });
    layout.addField(btnValidate);
    wrapper.add(new WAjaxControl(btnValidate, wrapper));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WMessages(com.github.bordertech.wcomponents.WMessages) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect)

Example 12 with WAjaxControl

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

the class WAjaxControlRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WButton trigger = new WButton("x");
    WPanel target1 = new WPanel();
    WPanel target2 = new WPanel();
    WPanel target3 = new WPanel();
    WAjaxControl control = new WAjaxControl(trigger);
    root.add(trigger);
    root.add(target1);
    root.add(target2);
    root.add(target3);
    root.add(control);
    // No Targets
    assertSchemaMatch(root);
    assertXpathEvaluatesTo("0", "count(//ui:ajaxtrigger)", root);
    // With Targets
    control.addTargets(new AjaxTarget[] { target1, target2, target3 });
    setActiveContext(createUIContext());
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(trigger.getId(), "//ui:ajaxtrigger/@triggerId", root);
    assertXpathNotExists("//ui:ajaxtrigger/@loadOnce", root);
    assertXpathNotExists("//ui:ajaxtrigger/@delay", root);
    assertXpathEvaluatesTo("3", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
    assertXpathEvaluatesTo(target1.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[1]/@targetId", root);
    assertXpathEvaluatesTo(target2.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[2]/@targetId", root);
    assertXpathEvaluatesTo(target3.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[3]/@targetId", root);
    control.setLoadOnce(true);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo("true", "//ui:ajaxtrigger/@loadOnce", root);
    // remove loadOnce then reset it using loadCount
    control.setLoadOnce(false);
    assertSchemaMatch(root);
    assertXpathNotExists("//ui:ajaxtrigger/@loadOnce", root);
    // With Targets and optional attributes
    // any number greateer than 0...
    control.setLoadCount(6);
    control.setDelay(1000);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(trigger.getId(), "//ui:ajaxtrigger/@triggerId", root);
    assertXpathEvaluatesTo("true", "//ui:ajaxtrigger/@loadOnce", root);
    assertXpathEvaluatesTo("1000", "//ui:ajaxtrigger/@delay", root);
    assertXpathEvaluatesTo("3", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 13 with WAjaxControl

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

the class WAjaxControlRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WAjaxControl component = new WAjaxControl(new WButton("x"));
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WAjaxControlRenderer);
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 14 with WAjaxControl

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

the class TextDuplicator method setupUI.

/**
 * Add the controls to the UI.
 * @param labelText the text to show in the duplicator field's label.
 */
private void setupUI(final String labelText) {
    WButton dupBtn = new WButton("Duplicate");
    dupBtn.setAction(new DuplicateAction());
    WButton clrBtn = new WButton("Clear");
    clrBtn.setAction(new ClearAction());
    add(new WLabel(labelText, textFld));
    add(textFld);
    add(dupBtn);
    add(clrBtn);
    add(new WAjaxControl(dupBtn, this));
    add(new WAjaxControl(clrBtn, this));
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 15 with WAjaxControl

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

the class WAudioExample method buildUI.

/**
 * Build the UI for this example.
 */
private void buildUI() {
    // build the configuration options UI.
    WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    layout.setMargin(new Margin(null, null, Size.LARGE, null));
    add(layout);
    layout.addField("Autoplay", cbAutoPlay);
    layout.addField("Loop", cbLoop);
    layout.addField("Disable", cbDisable);
    layout.addField("Show only play/pause", cbControls);
    layout.addField((WLabel) null, btnApply);
    // enable disable option only when control PLAY_PAUSE is used.
    WSubordinateControl control = new WSubordinateControl();
    add(control);
    Rule rule = new Rule();
    rule.setCondition(new Equal(cbControls, Boolean.TRUE.toString()));
    rule.addActionOnTrue(new Enable(cbDisable));
    rule.addActionOnFalse(new Disable(cbDisable));
    control.addRule(rule);
    // allow config to change without reloading the whole page.
    add(new WAjaxControl(btnApply, audio));
    // add the audio to the UI
    add(audio);
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Rule(com.github.bordertech.wcomponents.subordinate.Rule) Disable(com.github.bordertech.wcomponents.subordinate.Disable) Margin(com.github.bordertech.wcomponents.Margin)

Aggregations

WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)27 WButton (com.github.bordertech.wcomponents.WButton)18 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)16 Action (com.github.bordertech.wcomponents.Action)15 WHeading (com.github.bordertech.wcomponents.WHeading)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)10 WPanel (com.github.bordertech.wcomponents.WPanel)8 Margin (com.github.bordertech.wcomponents.Margin)6 WTextField (com.github.bordertech.wcomponents.WTextField)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)5 WLabel (com.github.bordertech.wcomponents.WLabel)5 AjaxTarget (com.github.bordertech.wcomponents.AjaxTarget)4 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)4 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)4 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 Rule (com.github.bordertech.wcomponents.subordinate.Rule)3 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)3 ArrayList (java.util.ArrayList)3 WComponent (com.github.bordertech.wcomponents.WComponent)2