use of com.github.bordertech.wcomponents.WSingleSelect in project wcomponents by BorderTech.
the class WSingleSelectRenderer_Test method testDoPaintOptions.
@Test
public void testDoPaintOptions() throws IOException, SAXException, XpathException {
String tooltip = "test tooltip";
String accessible = "test accessible text";
int rows = 2;
WSingleSelect single = new WSingleSelect(new String[] { "a", "b", "c" });
single.setDisabled(true);
setFlag(single, ComponentModel.HIDE_FLAG, true);
single.setMandatory(true);
single.setSubmitOnChange(true);
single.setToolTip(tooltip);
single.setAccessibleText(accessible);
single.setRows(rows);
assertSchemaMatch(single);
assertXpathEvaluatesTo("true", "//ui:listbox/@disabled", single);
assertXpathEvaluatesTo("true", "//ui:listbox/@hidden", single);
assertXpathEvaluatesTo("true", "//ui:listbox/@required", single);
assertXpathEvaluatesTo("true", "//ui:listbox/@submitOnChange", single);
assertXpathEvaluatesTo(tooltip, "//ui:listbox/@toolTip", single);
assertXpathEvaluatesTo(accessible, "//ui:listbox/@accessibleText", single);
assertXpathEvaluatesTo(Integer.toString(rows), "//ui:listbox/@rows", single);
assertXpathEvaluatesTo("true", "//ui:listbox/@single", single);
}
use of com.github.bordertech.wcomponents.WSingleSelect 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.WSingleSelect in project wcomponents by BorderTech.
the class WSingleSelectRenderer_Test method testDataList.
@Test
public void testDataList() throws IOException, SAXException, XpathException {
WSingleSelect single = new WSingleSelect(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE);
assertSchemaMatch(single);
assertXpathEvaluatesTo("0", "count(//ui:listbox/ui:option)", single);
assertXpathEvaluatesTo(single.getListCacheKey(), "//ui:listbox/@data", single);
// Set Selected
String code = single.getCode(single.getOptions().get(0), 0);
String desc = single.getDesc(single.getOptions().get(0), 0);
single.setSelected(code);
assertSchemaMatch(single);
assertXpathEvaluatesTo("1", "count(//ui:listbox/ui:option)", single);
assertXpathEvaluatesTo(desc, "//ui:listbox/ui:option[@value='" + code + "']/text()", single);
assertXpathEvaluatesTo(single.getListCacheKey(), "//ui:listbox/@data", single);
}
use of com.github.bordertech.wcomponents.WSingleSelect in project wcomponents by BorderTech.
the class WSingleSelectRenderer_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" };
WSingleSelect single = new WSingleSelect(options);
assertSchemaMatch(single);
assertXpathEvaluatesTo("2", "count(//ui:listbox/ui:option)", single);
assertXpathEvaluatesTo("1", "count(//ui:listbox/ui:optgroup)", single);
assertXpathEvaluatesTo("4", "count(//ui:listbox/ui:optgroup/ui:option)", single);
// Check grouped options
assertXpathEvaluatesTo(optionGroup.getDesc(), "//ui:listbox/ui:optgroup/@label", single);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(0), "//ui:listbox/ui:optgroup/ui:option[1]", single);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(1), "//ui:listbox/ui:optgroup/ui:option[2]", single);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(2), "//ui:listbox/ui:optgroup/ui:option[3]", single);
assertXpathEvaluatesTo((String) optionGroup.getOptions().get(3), "//ui:listbox/ui:optgroup/ui:option[4]", single);
// Check values
assertXpathEvaluatesTo("1", "//ui:listbox/ui:option[1]/@value", single);
assertXpathEvaluatesTo("2", "//ui:listbox/ui:optgroup/ui:option[1]/@value", single);
assertXpathEvaluatesTo("3", "//ui:listbox/ui:optgroup/ui:option[2]/@value", single);
assertXpathEvaluatesTo("4", "//ui:listbox/ui:optgroup/ui:option[3]/@value", single);
assertXpathEvaluatesTo("5", "//ui:listbox/ui:optgroup/ui:option[4]/@value", single);
assertXpathEvaluatesTo("6", "//ui:listbox/ui:option[2]/@value", single);
// Check selection
single.setSelected("A");
assertXpathEvaluatesTo("1", "count(//ui:option[@selected='true'])", single);
assertXpathExists("//ui:listbox/ui:option[text()='A'][@selected='true']", single);
single.setSelected("B.3");
assertXpathEvaluatesTo("1", "count(//ui:option[@selected='true'])", single);
assertXpathExists("//ui:listbox/ui:optgroup/ui:option[text()='B.3'][@selected='true']", single);
}
use of com.github.bordertech.wcomponents.WSingleSelect in project wcomponents by BorderTech.
the class WSingleSelectRenderer_Test method testIsNullOption.
@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
String[] options = new String[] { null, "", "A", "B", "C" };
WSingleSelect single = new WSingleSelect(options);
assertSchemaMatch(single);
assertXpathEvaluatesTo("5", "count(//ui:listbox/ui:option)", single);
assertXpathEvaluatesTo("", "//ui:listbox/ui:option[@value='']/text()", single);
for (int i = 0; i < options.length; i++) {
String code = single.optionToCode(options[i]);
String option = options[i];
if (option == null || option.equals("")) {
assertXpathEvaluatesTo("", "//ui:listbox/ui:option[@value='" + code + "']/text()", single);
assertXpathEvaluatesTo("true", "//ui:listbox/ui:option[@value='" + code + "']/@isNull", single);
} else {
assertXpathEvaluatesTo(option, "//ui:listbox/ui:option[@value='" + code + "']/text()", single);
assertXpathEvaluatesTo("", "//ui:listbox/ui:option[@value='" + code + "']/@isNull", single);
}
}
}
Aggregations