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));
}
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);
}
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);
}
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));
}
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);
}
Aggregations