use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WSingleSelectRenderer method doRender.
/**
* Paints the given WSingleSelect.
*
* @param component the WSingleSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSingleSelect listBox = (WSingleSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
String dataKey = listBox.getListCacheKey();
boolean readOnly = listBox.isReadOnly();
int rows = listBox.getRows();
xml.appendTagOpen("ui:listbox");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", listBox.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("data", dataKey != null, dataKey);
xml.appendOptionalAttribute("disabled", listBox.isDisabled(), "true");
xml.appendOptionalAttribute("required", listBox.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", listBox.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
xml.appendOptionalAttribute("rows", rows >= 2, rows);
}
xml.appendAttribute("single", "true");
xml.appendClose();
// Options
List<?> options = listBox.getOptions();
boolean renderSelectionsOnly = readOnly || dataKey != null;
if (options != null) {
int optionIndex = 0;
Object selectedOption = listBox.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
xml.appendTagOpen("ui:optgroup");
xml.appendAttribute("label", ((OptionGroup) option).getDesc());
xml.appendClose();
for (Object nestedOption : ((OptionGroup) option).getOptions()) {
renderOption(listBox, nestedOption, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(listBox, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(listBox, renderContext);
}
xml.appendEndTag("ui:listbox");
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiSelectPairRenderer_Test method testOptionGroups.
@Test
public void testOptionGroups() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup("B", Arrays.asList(new String[] { "B.1", "B.2", "B.3", "B.4" }));
Object[] options = new Object[] { "A", optionGroup, "C" };
WMultiSelectPair select = new WMultiSelectPair(options);
assertSchemaMatch(select);
assertXpathEvaluatesTo("2", "count(//ui:multiselectpair/ui:option)", select);
assertXpathEvaluatesTo("1", "count(//ui:multiselectpair/ui:optgroup)", select);
assertXpathEvaluatesTo("4", "count(//ui:multiselectpair/ui:optgroup/ui:option)", select);
// Check grouped options
assertXpathEvaluatesTo(optionGroup.getDesc(), "//ui:multiselectpair/ui:optgroup/@label", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(0), "//ui:multiselectpair/ui:optgroup/ui:option[1]", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(1), "//ui:multiselectpair/ui:optgroup/ui:option[2]", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(2), "//ui:multiselectpair/ui:optgroup/ui:option[3]", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(3), "//ui:multiselectpair/ui:optgroup/ui:option[4]", select);
// Check values
assertXpathEvaluatesTo("1", "//ui:multiselectpair/ui:option[1]/@value", select);
assertXpathEvaluatesTo("2", "//ui:multiselectpair/ui:optgroup/ui:option[1]/@value", select);
assertXpathEvaluatesTo("3", "//ui:multiselectpair/ui:optgroup/ui:option[2]/@value", select);
assertXpathEvaluatesTo("4", "//ui:multiselectpair/ui:optgroup/ui:option[3]/@value", select);
assertXpathEvaluatesTo("5", "//ui:multiselectpair/ui:optgroup/ui:option[4]/@value", select);
assertXpathEvaluatesTo("6", "//ui:multiselectpair/ui:option[2]/@value", select);
// Check selection
select.setSelected(Arrays.asList(new String[] { "A", "B.3" }));
assertXpathEvaluatesTo("2", "count(//ui:option[@selected='true'])", select);
assertXpathExists("//ui:multiselectpair/ui:option[text()='A'][@selected='true']", select);
assertXpathExists("//ui:multiselectpair/ui:optgroup/ui:option[text()='B.3'][@selected='true']", select);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiSelectPairRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup(getMaliciousAttribute("ui:optgroup"), Arrays.asList(new String[] { "dummy" }));
WMultiSelectPair select = new WMultiSelectPair(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent(), optionGroup }));
select.setAvailableListName(getMaliciousAttribute("ui:multiselectpair"));
select.setSelectedListName(getMaliciousAttribute("ui:multiselectpair"));
assertSafeContent(select);
select.setToolTip(getMaliciousAttribute("ui:multiselectpair"));
assertSafeContent(select);
select.setAccessibleText(getMaliciousAttribute("ui:multiselectpair"));
assertSafeContent(select);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiSelectPairRenderer_Test method testOptionGroupsWithShuffle.
@Test
public void testOptionGroupsWithShuffle() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup("B", Arrays.asList(new String[] { "B.1", "B.2", "B.3", "B.4" }));
Object[] options = new Object[] { "A", optionGroup, "C" };
WMultiSelectPair select = new WMultiSelectPair(options);
select.setShuffle(true);
assertSchemaMatch(select);
assertXpathEvaluatesTo("2", "count(//ui:multiselectpair/ui:option)", select);
assertXpathEvaluatesTo("1", "count(//ui:multiselectpair/ui:optgroup)", select);
assertXpathEvaluatesTo("4", "count(//ui:multiselectpair/ui:optgroup/ui:option)", select);
// Check grouped options
assertXpathEvaluatesTo(optionGroup.getDesc(), "//ui:multiselectpair/ui:optgroup/@label", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(0), "//ui:multiselectpair/ui:optgroup/ui:option[1]", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(1), "//ui:multiselectpair/ui:optgroup/ui:option[2]", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(2), "//ui:multiselectpair/ui:optgroup/ui:option[3]", select);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(3), "//ui:multiselectpair/ui:optgroup/ui:option[4]", select);
// Check values
assertXpathEvaluatesTo("1", "//ui:multiselectpair/ui:option[1]/@value", select);
assertXpathEvaluatesTo("2", "//ui:multiselectpair/ui:optgroup/ui:option[1]/@value", select);
assertXpathEvaluatesTo("3", "//ui:multiselectpair/ui:optgroup/ui:option[2]/@value", select);
assertXpathEvaluatesTo("4", "//ui:multiselectpair/ui:optgroup/ui:option[3]/@value", select);
assertXpathEvaluatesTo("5", "//ui:multiselectpair/ui:optgroup/ui:option[4]/@value", select);
assertXpathEvaluatesTo("6", "//ui:multiselectpair/ui:option[2]/@value", select);
// Check selection order
select.setSelected(Arrays.asList(new String[] { "A", "B.3", "B.1" }));
assertXpathEvaluatesTo("3", "count(//ui:option[@selected='true'])", select);
assertXpathExists("//ui:multiselectpair/ui:option[text()='A'][@selected='true']", select);
assertXpathExists("//ui:multiselectpair/ui:optgroup/ui:option[text()='B.3'][@selected='true']", select);
assertXpathExists("//ui:multiselectpair/ui:optgroup/ui:option[text()='B.1'][@selected='true']", select);
assertXpathEvaluatesTo("A", "//ui:multiselectpair/ui:option[@selected='true']/text()", select);
assertXpathEvaluatesTo("B.3", "//ui:multiselectpair/ui:optgroup[1]/ui:option[@selected='true'][1]/text()", select);
assertXpathEvaluatesTo("B.1", "//ui:multiselectpair/ui:optgroup[1]/ui:option[@selected='true'][2]/text()", select);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiSelectRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup(getMaliciousAttribute("ui:optgroup"), Arrays.asList(new String[] { "dummy" }));
WMultiSelect multi = new WMultiSelect(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent(), optionGroup }));
assertSafeContent(multi);
multi.setToolTip(getMaliciousAttribute("ui:listbox"));
assertSafeContent(multi);
multi.setAccessibleText(getMaliciousAttribute("ui:listbox"));
assertSafeContent(multi);
}
Aggregations