Search in sources :

Example 1 with OptionGroup

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");
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with OptionGroup

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);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) Test(org.junit.Test)

Example 3 with OptionGroup

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);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WDropdown(com.github.bordertech.wcomponents.WDropdown) Test(org.junit.Test)

Example 4 with OptionGroup

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);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown) Test(org.junit.Test)

Example 5 with OptionGroup

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);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Aggregations

OptionGroup (com.github.bordertech.wcomponents.OptionGroup)18 Test (org.junit.Test)12 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)6 WDropdown (com.github.bordertech.wcomponents.WDropdown)3 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)3 WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)3 WSingleSelect (com.github.bordertech.wcomponents.WSingleSelect)3 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)2 WMultiDropdown (com.github.bordertech.wcomponents.WMultiDropdown)2 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2