use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WSingleSelectRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
OptionGroup optionGroup = new OptionGroup(getMaliciousAttribute("ui:optgroup"), Arrays.asList(new String[] { "dummy" }));
WSingleSelect single = new WSingleSelect(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent(), optionGroup }));
assertSafeContent(single);
single.setToolTip(getMaliciousAttribute("ui:listbox"));
assertSafeContent(single);
single.setAccessibleText(getMaliciousAttribute("ui:listbox"));
assertSafeContent(single);
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WCheckBoxSelectRenderer method doRender.
/**
* Paints the given WCheckBoxSelect.
*
* @param component the WCheckBoxSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCheckBoxSelect select = (WCheckBoxSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
int cols = select.getButtonColumns();
boolean readOnly = select.isReadOnly();
xml.appendTagOpen("ui:checkboxselect");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", select.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
int min = select.getMinSelect();
int max = select.getMaxSelect();
xml.appendOptionalAttribute("disabled", select.isDisabled(), "true");
xml.appendOptionalAttribute("required", select.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", select.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
xml.appendOptionalAttribute("min", min > 0, min);
xml.appendOptionalAttribute("max", max > 0, max);
}
xml.appendOptionalAttribute("frameless", select.isFrameless(), "true");
switch(select.getButtonLayout()) {
case COLUMNS:
xml.appendAttribute("layout", "column");
xml.appendOptionalAttribute("layoutColumnCount", cols > 0, cols);
break;
case FLAT:
xml.appendAttribute("layout", "flat");
break;
case STACKED:
xml.appendAttribute("layout", "stacked");
break;
default:
throw new SystemException("Unknown layout type: " + select.getButtonLayout());
}
xml.appendClose();
// Options
List<?> options = select.getOptions();
boolean renderSelectionsOnly = readOnly;
if (options != null) {
int optionIndex = 0;
List<?> selections = select.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
throw new SystemException("Option groups not supported in WCheckBoxSelect.");
} else {
renderOption(select, option, optionIndex++, xml, selections, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(select, renderContext);
}
xml.appendEndTag("ui:checkboxselect");
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WDropdownRenderer method doRender.
/**
* Paints the given WDropdown.
*
* @param component the WDropdown to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDropdown dropdown = (WDropdown) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = dropdown.isReadOnly();
String dataKey = dropdown.getListCacheKey();
// Start tag
xml.appendTagOpen("ui:dropdown");
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, dataKey);
xml.appendOptionalAttribute("disabled", dropdown.isDisabled(), "true");
xml.appendOptionalAttribute("required", dropdown.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", dropdown.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", dropdown.getToolTip());
xml.appendOptionalAttribute("accessibleText", dropdown.getAccessibleText());
int optionWidth = dropdown.getOptionWidth();
xml.appendOptionalAttribute("optionWidth", optionWidth > 0, optionWidth);
xml.appendOptionalAttribute("type", getTypeAsString(dropdown.getType()));
}
xml.appendClose();
// Options
List<?> options = dropdown.getOptions();
Object selectedOption = dropdown.getSelected();
// For an editable dropdown (combo box), the selected option may not be in the list.
if (dropdown.getType() == WDropdown.DropdownType.COMBO && selectedOption != null && (options == null || !options.contains(selectedOption))) {
xml.appendTagOpen("ui:option");
xml.appendAttribute("value", selectedOption.toString());
xml.appendAttribute("selected", "true");
xml.appendClose();
xml.appendEscaped(selectedOption.toString());
xml.appendEndTag("ui:option");
}
if (options != null) {
int optionIndex = 0;
boolean renderSelectionsOnly = readOnly || dataKey != null;
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, selectedOption, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(dropdown, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(dropdown, renderContext);
}
// End tag
xml.appendEndTag("ui:dropdown");
}
use of com.github.bordertech.wcomponents.OptionGroup in project wcomponents by BorderTech.
the class WMultiSelectRenderer method doRender.
/**
* Paints the given WMultiSelect.
*
* @param component the WMultiSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMultiSelect listBox = (WMultiSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
String dataKey = listBox.getListCacheKey();
boolean readOnly = listBox.isReadOnly();
int rows = listBox.getRows();
int min = listBox.getMinSelect();
int max = listBox.getMaxSelect();
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 && !readOnly, 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.appendOptionalAttribute("min", min > 0, min);
xml.appendOptionalAttribute("max", max > 0, max);
}
xml.appendClose();
// Options
List<?> options = listBox.getOptions();
boolean renderSelectionsOnly = readOnly || dataKey != null;
if (options != null) {
int optionIndex = 0;
List<?> selections = 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, selections, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(listBox, option, optionIndex++, xml, selections, 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 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);
}
}
Aggregations