use of com.github.bordertech.wcomponents.validation.ValidatingAction in project wcomponents by BorderTech.
the class ButtonOptionsExample method getButtonControls.
/**
* build the button controls field set.
*
* @param errors the error pane from the page.
* @return a field set for the controls.
*/
private WFieldSet getButtonControls(final WValidationErrors errors) {
// Options Layout
WFieldSet fieldSet = new WFieldSet("Button configuration");
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(30);
layout.addField("Text", tfButtonLabel);
layout.addField("AccessKey", tfAccesskey);
layout.addField("Render as link", cbRenderAsLink);
layout.addField("Disabled", cbDisabled);
layout.addField("setImage ('/image/pencil.png')", cbSetImage);
layout.addField("Image Position", ddImagePosition);
// Apply Button
WButton apply = new WButton("Apply");
apply.setAction(new ValidatingAction(errors, fieldSet) {
@Override
public void executeOnValid(final ActionEvent event) {
applySettings();
}
});
fieldSet.add(layout);
fieldSet.add(apply);
return fieldSet;
}
use of com.github.bordertech.wcomponents.validation.ValidatingAction in project wcomponents by BorderTech.
the class InputBeanBindingExample method addButtons.
/**
* Setup the action buttons.
*/
private void addButtons() {
// Validation Button
WButton buttonValidate = new WButton("Validate and Update Bean");
add(buttonValidate);
buttonValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {
@Override
public void executeOnValid(final ActionEvent event) {
WebUtilities.updateBeanValue(layout);
messages.success("OK");
}
});
// Update Bean
WButton buttonUpdate = new WButton("Update Bean");
add(buttonUpdate);
buttonUpdate.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
WebUtilities.updateBeanValue(layout);
}
});
// Reset Inputs
WButton buttonReset = new WButton("Reset Inputs");
add(buttonReset);
buttonReset.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
layout.reset();
}
});
// Reset Bean
WButton buttonBean = new WButton("Reset Bean");
add(buttonBean);
buttonBean.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
InputBeanBindingExample.this.setBean(new MyDemoBean());
}
});
add(new WButton("submit"));
}
use of com.github.bordertech.wcomponents.validation.ValidatingAction in project wcomponents by BorderTech.
the class WButtonRenderer_Test method testAllOptions.
@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
WButton button = new WButton("All");
button.setDisabled(true);
setFlag(button, ComponentModel.HIDE_FLAG, true);
button.setToolTip("Title");
button.setAccessKey('T');
button.setImageUrl("http://localhost/image.png");
button.setImagePosition(ImagePosition.EAST);
button.setRenderAsLink(true);
button.setAjaxTarget(new WTextField());
button.setPopupTrigger(true);
setActiveContext(createUIContext());
WPanel validationComponent = new WPanel();
button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {
@Override
public void executeOnValid(final ActionEvent event) {
// Do nothing
}
});
WContainer root = new WContainer();
root.add(button);
root.add(validationComponent);
assertXpathExists("//html:button[@id]", button);
assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
assertXpathEvaluatesTo(button.getText(), "//html:button", button);
assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
button.setImagePosition(ImagePosition.NORTH);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
button.setImagePosition(ImagePosition.SOUTH);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
button.setImagePosition(ImagePosition.WEST);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
button.setClientCommandOnly(true);
assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
use of com.github.bordertech.wcomponents.validation.ValidatingAction 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.validation.ValidatingAction in project wcomponents by BorderTech.
the class GridLayoutOptionsExample method getLayoutControls.
/**
* build the list controls field set.
*
* @param errors the error box to be linked to the apply button.
* @return a field set for the controls.
*/
private WFieldSet getLayoutControls(final WValidationErrors errors) {
// Options Layout
WFieldSet fieldSet = new WFieldSet("List configuration");
WFieldLayout layout = new ControlFieldLayout();
fieldSet.add(layout);
// options.
columnCount.setDecimalPlaces(0);
columnCount.setMinValue(0);
columnCount.setNumber(DEFAULT_COLUMN_COUNT);
columnCount.setMandatory(true);
layout.addField("Number of Columns", columnCount);
rowCount.setDecimalPlaces(0);
rowCount.setMinValue(0);
rowCount.setNumber(DEFAULT_ROW_COUNT);
rowCount.setMandatory(true);
layout.addField("Number of Rows", rowCount);
hGap.setDecimalPlaces(0);
hGap.setMinValue(0);
hGap.setNumber(0);
hGap.setMandatory(true);
layout.addField("Horizontal Gap", hGap);
vGap.setDecimalPlaces(0);
vGap.setMinValue(0);
vGap.setNumber(0);
vGap.setMandatory(true);
layout.addField("Vertical Gap", vGap);
boxCount.setDecimalPlaces(0);
boxCount.setMinValue(0);
boxCount.setNumber(DEFAULT_BOX_COUNT);
boxCount.setMandatory(true);
layout.addField("Number of Boxes", boxCount);
layout.addField("Visible", cbVisible);
layout.addField("Allow responsive design", cbResponsive);
// Apply Button
WButton apply = new WButton("Apply");
apply.setAction(new ValidatingAction(errors, this) {
@Override
public void executeOnValid(final ActionEvent event) {
applySettings();
}
});
layout.addField(apply);
fieldSet.add(new WAjaxControl(apply, container));
fieldSet.setMargin(new Margin(null, null, Size.LARGE, null));
return fieldSet;
}
Aggregations