use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method setupTrigger.
/**
* Setup the trigger for the subordinate control.
*/
private void setupTrigger() {
String label = drpTriggerType.getSelected() + " Trigger";
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(LABEL_WIDTH);
buildControlPanel.add(layout);
switch((TriggerType) drpTriggerType.getSelected()) {
case RadioButtonGroup:
trigger = new RadioButtonGroup();
WFieldSet rbSet = new WFieldSet("Select an option");
RadioButtonGroup group = (RadioButtonGroup) trigger;
WRadioButton rb1 = group.addRadioButton("A");
WRadioButton rb2 = group.addRadioButton("B");
WRadioButton rb3 = group.addRadioButton("C");
rbSet.add(group);
rbSet.add(rb1);
rbSet.add(new WLabel("A", rb1));
rbSet.add(new WText("\u00a0"));
rbSet.add(rb2);
rbSet.add(new WLabel("B", rb2));
rbSet.add(new WText("\u00a0"));
rbSet.add(rb3);
rbSet.add(new WLabel("C", rb3));
layout.addField(label, rbSet);
return;
case CheckBox:
trigger = new WCheckBox();
break;
case CheckBoxSelect:
trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
break;
case DateField:
trigger = new WDateField();
break;
case Dropdown:
trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
break;
case EmailField:
trigger = new WEmailField();
break;
case MultiSelect:
trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
break;
case MultiSelectPair:
trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
break;
case NumberField:
trigger = new WNumberField();
break;
case PartialDateField:
trigger = new WPartialDateField();
break;
case PasswordField:
trigger = new WPasswordField();
break;
case PhoneNumberField:
trigger = new WPhoneNumberField();
break;
case RadioButtonSelect:
trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
break;
case SingleSelect:
trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
break;
case TextArea:
trigger = new WTextArea();
((WTextArea) trigger).setMaxLength(1000);
break;
case TextField:
trigger = new WTextField();
break;
default:
throw new SystemException("Trigger type not valid");
}
layout.addField(label, trigger);
}
use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.
the class WLabelExample method addNullLabelExample.
/**
* Example of when and how to use a null WLabel.
*/
private void addNullLabelExample() {
add(new WHeading(HeadingLevel.H2, "How to use accessible null WLabels"));
add(new ExplanatoryText("These examples shows how sometime a null WLabel is the right thing to do." + "\n This example uses a WFieldSet as the labelled component and it has its own \"label\"."));
// We want to add a WFieldSet to a WFieldLayout but without an extra label.
WFieldLayout fieldsFlat = new WFieldLayout();
fieldsFlat.setMargin(new Margin(null, null, Size.XL, null));
add(fieldsFlat);
WFieldSet fs = new WFieldSet("Do you like Bananas?");
fieldsFlat.addField((WLabel) null, fs);
// now add the WRadioButtons to the WFieldSet using an inner WFieldLayout
WFieldLayout innerLayout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
// The content will be a group of WRadioButtons
RadioButtonGroup group1 = new RadioButtonGroup();
WRadioButton rb1 = group1.addRadioButton(1);
WRadioButton rb2 = group1.addRadioButton(2);
// make the labels for the radio buttons
WLabel rb1Label = new WLabel("", rb1);
WImage labelImage = new WImage("/image/success.png", "I still like bananas");
labelImage.setHtmlClass("wc-valign-bottom");
rb1Label.add(labelImage);
WLabel rb2Label = new WLabel("", rb2);
labelImage = new WImage("/image/error.png", "I still dislike bananas");
labelImage.setHtmlClass("wc-valign-bottom");
rb2Label.add(labelImage);
innerLayout.addField(rb1Label, rb1);
innerLayout.addField(rb2Label, rb2);
// add the content to the WFieldLayout - the order really doesn't matter.
fs.add(group1);
fs.add(innerLayout);
}
use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.
the class AbstractCompare method getCompareValue.
/**
* Get the value to use in the compare.
* <p>
* It will return the same "value" the client would have used in its subordinate logic.
* </p>
* <p>
* The compare value will either be (i) a date formatted String for WDateFields, (ii) a BigDecimal for WNumberFields
* or (iii) a String value.
* </p>
*
* @return the value to be used for the compare.
*/
protected Object getCompareValue() {
// Date Compare (Use Date Formatted String - YYYY-MM-DD)
if (trigger instanceof WDateField) {
return value == null ? null : new SimpleDateFormat(INTERNAL_DATE_FORMAT).format(value);
} else if (trigger instanceof WNumberField) {
// Number Compare (Use Number Object)
return value;
} else if (trigger instanceof AbstractWSelectList) {
// String Compare - List (Use the Option's Code)
final AbstractWSelectList listTrigger = (AbstractWSelectList) trigger;
final List<?> options = listTrigger.getOptions();
// No options, just return the compare value (so that a test against null works correctly)
if (options == null || options.isEmpty()) {
return value == null ? null : value.toString();
}
// Check if the value is a valid option allowing for "Legacy" matching
if (SelectListUtil.containsOptionWithMatching(options, value)) {
Object option = SelectListUtil.getOptionWithMatching(options, value);
String code = listTrigger.optionToCode(option);
return code;
}
// Return the value as a String - Treat empty the same as null
return (value == null || Util.empty(value.toString())) ? null : value.toString();
} else if (trigger instanceof RadioButtonGroup && value instanceof WRadioButton) {
// String Compare for RadioButtonGroup and value is WRadioButton (Use the button value)
// Note - This is only for backward compatibility where projects have used a radio button
// in the trigger. Projects should use the value expected, not the radio button.
// If the radio button passed into the compare is used in a repeater, then this compare will not work.
String data = ((WRadioButton) value).getValue();
// Treat empty the same as null
return Util.empty(data) ? null : data;
} else {
// Treat empty the same as null
return (value == null || Util.empty(value.toString())) ? null : value.toString();
}
}
use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.
the class WRadioButtonRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
RadioButtonGroup group = new RadioButtonGroup();
WRadioButton button = group.addRadioButton(1);
button.setVisible(true);
assertSchemaMatch(button);
assertXpathExists("//ui:radiobutton", button);
assertXpathEvaluatesTo(button.getId(), "//ui:radiobutton/@id", button);
assertXpathEvaluatesTo(button.getGroupName(), "//ui:radiobutton/@groupName", button);
assertXpathEvaluatesTo(button.getValue(), "//ui:radiobutton/@value", button);
assertXpathNotExists("//ui:radiobutton/@submitOnChange", button);
// Check selected
assertXpathNotExists("//ui:radiobutton/@selected", button);
button.setSelected(true);
assertSchemaMatch(button);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@selected", button);
// Check disabled
assertXpathNotExists("//ui:radiobutton/@disabled", button);
button.setDisabled(true);
assertSchemaMatch(button);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@disabled", button);
// Check hidden
assertXpathNotExists("//ui:radiobutton/@hidden", button);
setFlag(button, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(button);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@hidden", button);
// Check required
assertXpathNotExists("//ui:radiobutton/@required", button);
group.setMandatory(true);
assertSchemaMatch(button);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@required", button);
// Check toolTip
String toolTip = "WRadioButton_Test.testRenderedFormat.toolTip";
button.setToolTip(toolTip);
assertSchemaMatch(button);
assertXpathEvaluatesTo(toolTip, "//ui:radiobutton/@toolTip", button);
button.setToolTip(null);
assertSchemaMatch(button);
assertXpathNotExists("//ui:radiobutton/@toolTip", button);
// Check submitOnChange
group = new RadioButtonGroup();
button = group.addRadioButton(1);
group.setSubmitOnChange(true);
assertSchemaMatch(button);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@submitOnChange", button);
}
use of com.github.bordertech.wcomponents.RadioButtonGroup in project wcomponents by BorderTech.
the class WRadioButtonRenderer_Test method testIsNullOption.
@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
WPanel root = new WPanel();
RadioButtonGroup group = new RadioButtonGroup();
root.add(group);
WRadioButton button1 = group.addRadioButton(null);
WRadioButton button2 = group.addRadioButton("");
WRadioButton button3 = group.addRadioButton("A");
root.add(button1);
root.add(button2);
root.add(button3);
assertSchemaMatch(root);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@isNull", button1);
assertXpathEvaluatesTo("true", "//ui:radiobutton/@isNull", button2);
assertXpathEvaluatesTo("", "//ui:radiobutton/@isNull", button3);
}
Aggregations