use of com.github.bordertech.wcomponents.WRadioButton 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.WRadioButton 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.WRadioButton 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);
}
use of com.github.bordertech.wcomponents.WRadioButton in project wcomponents by BorderTech.
the class ByWComponent method findValue.
/**
* Narrows down the search for a WebElement to find the appropriate value.
*
* @param current the current WebElement which was reached during a search.
* @param component the component corresponding to the given WebElement.
* @param context the context for the component.
* @param value the value to search for.
* @return the WebElement with the given value, or null if not found.
*/
public static WebElement findValue(final WebElement current, final WComponent component, final UIContext context, final Object value) {
// If not narrowing down the search, just return the current element.
if (value == null) {
return current;
}
UIContextHolder.pushContext(context);
try {
if (component instanceof AbstractWSelectList) {
AbstractWSelectList list = (AbstractWSelectList) component;
List<?> options = list.getOptions();
if (options != null) {
for (int i = 0; i < options.size(); i++) {
Object option = options.get(i);
if (Util.equals(value, option) || Util.equals(value.toString(), list.getDesc(option, i))) {
return current.findElement(By.xpath(".//*[@value='" + list.getCode(option, i) + "']"));
}
}
}
// Not found
return null;
} else if (component instanceof WRadioButton) {
return value.equals(((WRadioButton) component).getValue()) ? current : null;
} else {
return current.findElement(By.xpath(".//*[@value='" + WebUtilities.encode(String.valueOf(value)) + "']"));
}
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.WRadioButton 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);
}
Aggregations