use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiDropdownRenderer method doRender.
/**
* Paints the given WMultiDropdown.
*
* @param component the WMultiDropdown to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMultiDropdown dropdown = (WMultiDropdown) component;
XmlStringBuilder xml = renderContext.getWriter();
String dataKey = dropdown.getListCacheKey();
boolean readOnly = dropdown.isReadOnly();
xml.appendTagOpen("ui:multidropdown");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", dropdown.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("data", dataKey != null && !readOnly, dataKey);
xml.appendOptionalAttribute("disabled", dropdown.isDisabled(), "true");
xml.appendOptionalAttribute("required", dropdown.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", dropdown.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
int min = dropdown.getMinSelect();
int max = dropdown.getMaxSelect();
xml.appendOptionalAttribute("min", min > 0, min);
xml.appendOptionalAttribute("max", max > 0, max);
xml.appendOptionalAttribute("title", I18nUtilities.format(null, InternalMessages.DEFAULT_MULTI_FORM_COMPONENT_TIP));
}
xml.appendClose();
// Options
List<?> options = dropdown.getOptions();
boolean renderSelectionsOnly = dropdown.isReadOnly() || dataKey != null;
if (options != null) {
int optionIndex = 0;
List<?> selections = dropdown.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(dropdown, nestedOption, optionIndex++, xml, selections, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(dropdown, option, optionIndex++, xml, selections, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(dropdown, renderContext);
}
// End tag
xml.appendEndTag("ui:multidropdown");
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WCheckBoxSelectRenderer_Test method testOptGroupException.
@Test(expected = SystemException.class)
public void testOptGroupException() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup("Test", Arrays.asList(new String[] { "A", "B" }));
WCheckBoxSelect group = new WCheckBoxSelect(Arrays.asList(new Object[] { "X", optionGroup }));
assertSchemaMatch(group);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WDropdownRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup(getMaliciousAttribute("ui:optgroup"), Arrays.asList(new String[] { "dummy" }));
WDropdown drop = new WDropdown(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent(), optionGroup }));
assertSafeContent(drop);
drop.setToolTip(getMaliciousAttribute("ui:dropdown"));
assertSafeContent(drop);
drop.setAccessibleText(getMaliciousAttribute("ui:dropdown"));
assertSafeContent(drop);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiDropdownRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup(getMaliciousAttribute("ui:optgroup"), Arrays.asList(new String[] { "dummy" }));
WMultiDropdown drop = new WMultiDropdown(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent(), optionGroup }));
assertSafeContent(drop);
drop.setToolTip(getMaliciousAttribute("ui:multidropdown"));
assertSafeContent(drop);
drop.setAccessibleText(getMaliciousAttribute("ui:multidropdown"));
assertSafeContent(drop);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WRadioButtonSelectRenderer_Test method testOptGroupException.
@Test(expected = SystemException.class)
public void testOptGroupException() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup("Test", Arrays.asList(new String[] { "A", "B" }));
WRadioButtonSelect group = new WRadioButtonSelect(Arrays.asList(new Object[] { "X", optionGroup }));
assertSchemaMatch(group);
}
Aggregations