use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer method doRender.
/**
* Paints the given WRadioButtonSelect.
*
* @param component the WRadioButtonSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WRadioButtonSelect rbSelect = (WRadioButtonSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
int cols = rbSelect.getButtonColumns();
boolean readOnly = rbSelect.isReadOnly();
xml.appendTagOpen("ui:radiobuttonselect");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", rbSelect.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("disabled", rbSelect.isDisabled(), "true");
xml.appendOptionalAttribute("required", rbSelect.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", rbSelect.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
}
xml.appendOptionalAttribute("frameless", rbSelect.isFrameless(), "true");
switch(rbSelect.getButtonLayout()) {
case COLUMNS:
xml.appendAttribute("layout", "column");
xml.appendOptionalAttribute("layoutColumnCount", cols > 0, String.valueOf(cols));
break;
case FLAT:
xml.appendAttribute("layout", "flat");
break;
case STACKED:
xml.appendAttribute("layout", "stacked");
break;
default:
throw new SystemException("Unknown radio button layout: " + rbSelect.getButtonLayout());
}
xml.appendClose();
// Options
List<?> options = rbSelect.getOptions();
boolean renderSelectionsOnly = readOnly;
if (options != null) {
int optionIndex = 0;
Object selectedOption = rbSelect.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
throw new SystemException("Option groups not supported in WRadioButtonSelect.");
} else {
renderOption(rbSelect, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(rbSelect, renderContext);
}
xml.appendEndTag("ui:radiobuttonselect");
if (rbSelect.isAjax()) {
paintAjax(rbSelect, xml);
}
}
use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WRadioButtonSelect component = new WRadioButtonSelect();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WRadioButtonSelectRenderer);
}
use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer_Test method testReadOnly.
@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
WRadioButtonSelect buttonGroup = new WRadioButtonSelect(new String[] { "a", "b", "c" });
// Check Readonly - only render selected option
buttonGroup.setReadOnly(true);
buttonGroup.setSelected("b");
assertSchemaMatch(buttonGroup);
assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@readOnly", buttonGroup);
assertXpathEvaluatesTo("1", "count(//ui:radiobuttonselect/ui:option[@selected='true'])", buttonGroup);
assertXpathEvaluatesTo("b", "//ui:radiobuttonselect/ui:option[@selected='true']", buttonGroup);
}
use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer_Test method testIsNullOption.
@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
String[] options = new String[] { null, "", "A", "B", "C" };
WRadioButtonSelect select = new WRadioButtonSelect(options);
assertSchemaMatch(select);
assertXpathEvaluatesTo("5", "count(//ui:radiobuttonselect/ui:option)", select);
assertXpathEvaluatesTo("", "//ui:radiobuttonselect/ui:option[@value='']/text()", select);
for (int i = 0; i < options.length; i++) {
String code = select.optionToCode(options[i]);
String option = options[i];
if (option == null || option.equals("")) {
assertXpathEvaluatesTo("", "//ui:radiobuttonselect/ui:option[@value='" + code + "']/text()", select);
assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/ui:option[@value='" + code + "']/@isNull", select);
} else {
assertXpathEvaluatesTo(option, "//ui:radiobuttonselect/ui:option[@value='" + code + "']/text()", select);
assertXpathEvaluatesTo("", "//ui:radiobuttonselect/ui:option[@value='" + code + "']/@isNull", select);
}
}
}
use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WRadioButtonSelect group = new WRadioButtonSelect(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent() }));
assertSafeContent(group);
group.setToolTip(getMaliciousAttribute("ui:radiobuttonselect"));
assertSafeContent(group);
group.setAccessibleText(getMaliciousAttribute("ui:radiobuttonselect"));
assertSafeContent(group);
}
Aggregations