use of com.github.bordertech.wcomponents.WMessageBox in project wcomponents by BorderTech.
the class WButtonExample method addAntiPatternExamples.
/**
* Examples of what not to do when using WButton.
*/
private void addAntiPatternExamples() {
add(new WHeading(HeadingLevel.H2, "WButton anti-pattern examples"));
add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
add(new WHeading(HeadingLevel.H3, "WButton without a good label"));
add(new WButton("\u2002"));
add(new ExplanatoryText("A button without a text label is very bad"));
add(new WHeading(HeadingLevel.H3, "WButton with a WImage but without a good label"));
WButton button = new WButton("");
button.setImage("/image/help.png");
add(button);
add(new ExplanatoryText("A button without a text label is very bad, even if you think the image is sufficient. The text label becomes the image alt text."));
}
use of com.github.bordertech.wcomponents.WMessageBox in project wcomponents by BorderTech.
the class WRadioButtonSelectExample method addAntiPatternExamples.
/**
* Examples of what not to do when using WRadioButtonSelect.
*/
private void addAntiPatternExamples() {
add(new WHeading(HeadingLevel.H2, "WRadioButtonSelect anti-pattern examples"));
add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
// Even compound controls need a label
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with no labelling component"));
add(new ExplanatoryText("All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip."));
add(new WRadioButtonSelect("australian_state"));
// submitOnChange is a WRadioButtonSelect no no!!
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with submitOnChange"));
add(new ExplanatoryText("SubmitOnChange is bad in most cases but terrible with radio buttons because there is no way to change the selection" + " between non-contiguous options using the keyboard without having multiple page submits.\nIn the following example try to change " + "the selection from 'Outside Australia' to 'Queensland' using only your keyboard. To make this easier the WRadioButtonSelect has" + " an access key of 'M'"));
final WRadioButtonSelect select = new SelectWithSelection("australian_state");
final WTextField selected = new WTextField();
selected.setReadOnly(true);
select.setActionOnChange(new Action() {
@Override
public void execute(final ActionEvent event) {
// does not matter what this is
selected.setText(select.getValueAsString());
}
});
select.setSubmitOnChange(true);
// now put them all into the UI
WFieldLayout layout = new WFieldLayout();
add(layout);
WField selectField = layout.addField("Make a selection to update the page", select);
selectField.getLabel().setAccessKey('M');
layout.addField("Selected option", selected);
// Too many options anti-pattern
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with too many options"));
add(new ExplanatoryText("Don't use a WRadioButtonSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
// use the country code list at your peril!!
WRadioButtonSelect rbsTooBig = new WRadioButtonSelect(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" });
rbsTooBig.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
rbsTooBig.setButtonColumns(6);
rbsTooBig.setFrameless(true);
rbsTooBig.setToolTip("Select your country of birth");
add(rbsTooBig);
// Don't use a radioButtonSelect if the user can make no selection unless you provide a null option
add(new WHeading(HeadingLevel.H3, "Optional WRadioButtonSelect with no null option"));
add(new ExplanatoryText("Once a radio button group has a selection it cannot be removed. If a WRadioButtonSelect is not mandatory it should" + " include a 'none of these' type null option.\nWhat happens if you make a selection in the following but then change your mind" + " (even ugly chairs are not your scene). To concentrate the mind I have made a selection for you."));
WRadioButtonSelect noneOfTheAboveSelect = new SelectWithSelection(new String[] { "spike", "broken glass", "ugly chair", "wet paint" });
noneOfTheAboveSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
noneOfTheAboveSelect.setFrameless(true);
layout = new WFieldLayout();
add(layout);
layout.addField("Where would you like to sit?", noneOfTheAboveSelect);
// don't use a yes/no group of radio buttons for something which should be a checkbox
add(new WHeading(HeadingLevel.H3, "Yes/No options"));
add(new ExplanatoryText("If the only answers to your question is one of yes or no then you do not have a group of radio buttons, you have a check box.\n" + "In the following example the WRadioButtonSelect should be a WCheckBox and the label be 'I agree to the terms and conditions'"));
layout = new WFieldLayout();
add(layout);
WRadioButtonSelect yesNoSelect = new WRadioButtonSelect(new String[] { "yes", "no" });
yesNoSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
yesNoSelect.setFrameless(true);
layout.addField("Do you agree to the terms and conditions?", yesNoSelect);
add(new WHeading(HeadingLevel.H3, "No options"));
add(new ExplanatoryText("An interactive WRadioButtonSelect with no options is rather pointless."));
layout = new WFieldLayout();
add(layout);
layout.addField("Select from no options", new WRadioButtonSelect());
}
use of com.github.bordertech.wcomponents.WMessageBox in project wcomponents by BorderTech.
the class WMessageBoxRenderer method doRender.
/**
* Paints the given WMessageBox.
*
* @param component the WMessageBox to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMessageBox messageBox = (WMessageBox) component;
XmlStringBuilder xml = renderContext.getWriter();
if (messageBox.hasMessages()) {
xml.appendTagOpen("ui:messagebox");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
switch(messageBox.getType()) {
case SUCCESS:
xml.appendOptionalAttribute("type", "success");
break;
case INFO:
xml.appendOptionalAttribute("type", "info");
break;
case WARN:
xml.appendOptionalAttribute("type", "warn");
break;
case ERROR:
default:
xml.appendOptionalAttribute("type", "error");
break;
}
xml.appendOptionalAttribute("title", messageBox.getTitleText());
xml.appendClose();
for (String message : messageBox.getMessages()) {
xml.appendTag("ui:message");
xml.print(message);
xml.appendEndTag("ui:message");
}
xml.appendEndTag("ui:messagebox");
}
}
use of com.github.bordertech.wcomponents.WMessageBox in project wcomponents by BorderTech.
the class WMessageBoxRenderer_Test method testDoPaintWhenEmpty.
@Test
public void testDoPaintWhenEmpty() throws IOException, SAXException, XpathException {
WMessageBox messageBox = new WMessageBox(WMessageBox.SUCCESS);
assertSchemaMatch(messageBox);
assertXpathNotExists("//ui:messagebox", messageBox);
}
use of com.github.bordertech.wcomponents.WMessageBox in project wcomponents by BorderTech.
the class WCheckBoxSelectExample method addAntiPatternExamples.
/**
* Examples of what not to do when using WCheckBoxSelect.
*/
private void addAntiPatternExamples() {
add(new WHeading(HeadingLevel.H2, "WCheckBoxSelect anti-pattern examples"));
add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with submitOnChange"));
WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
add(layout);
WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
select.setSubmitOnChange(true);
layout.addField("Select a state or territory with auto save", select);
select = new WCheckBoxSelect("australian_state");
select.setSubmitOnChange(true);
layout.addField("Select a state or territory with auto save and hint", select).getLabel().setHint("This is a hint");
// Even compound controls need a label
add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with no labelling component"));
add(new ExplanatoryText("All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip."));
add(new WCheckBoxSelect("australian_state"));
// Too many options anti-pattern
add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with too many options"));
add(new ExplanatoryText("Don't use a WCheckBoxSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
select = new WCheckBoxSelect(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" });
select.setButtonLayout(WCheckBoxSelect.LAYOUT_COLUMNS);
select.setButtonColumns(6);
select.setFrameless(true);
add(new WLabel("Select your country of birth", select));
add(select);
add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with no options."));
add(new ExplanatoryText("An interactive WCheckBoxSelect with no options is rather pointless."));
select = new WCheckBoxSelect();
add(new WLabel("WCheckBoxSelect with no options", select));
add(select);
}
Aggregations