Search in sources :

Example 16 with WRadioButtonSelect

use of com.github.bordertech.wcomponents.WRadioButtonSelect 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);
    }
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) SystemException(com.github.bordertech.wcomponents.util.SystemException) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 17 with WRadioButtonSelect

use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.

the class WRadioButtonSelectRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WRadioButtonSelect component = new WRadioButtonSelect();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WRadioButtonSelectRenderer);
}
Also used : WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Example 18 with WRadioButtonSelect

use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.

the class WRadioButtonSelectRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    WRadioButtonSelect buttonGroup = new WRadioButtonSelect(new String[] { "a", "b", "c" });
    // Check Readonly - only render selected option
    buttonGroup.setReadOnly(true);
    buttonGroup.setSelected("b");
    assertSchemaMatch(buttonGroup);
    assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/@readOnly", buttonGroup);
    assertXpathEvaluatesTo("1", "count(//ui:radiobuttonselect/ui:option[@selected='true'])", buttonGroup);
    assertXpathEvaluatesTo("b", "//ui:radiobuttonselect/ui:option[@selected='true']", buttonGroup);
}
Also used : WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Example 19 with WRadioButtonSelect

use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.

the class WRadioButtonSelectRenderer_Test method testIsNullOption.

@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
    String[] options = new String[] { null, "", "A", "B", "C" };
    WRadioButtonSelect select = new WRadioButtonSelect(options);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("5", "count(//ui:radiobuttonselect/ui:option)", select);
    assertXpathEvaluatesTo("", "//ui:radiobuttonselect/ui:option[@value='']/text()", select);
    for (int i = 0; i < options.length; i++) {
        String code = select.optionToCode(options[i]);
        String option = options[i];
        if (option == null || option.equals("")) {
            assertXpathEvaluatesTo("", "//ui:radiobuttonselect/ui:option[@value='" + code + "']/text()", select);
            assertXpathEvaluatesTo("true", "//ui:radiobuttonselect/ui:option[@value='" + code + "']/@isNull", select);
        } else {
            assertXpathEvaluatesTo(option, "//ui:radiobuttonselect/ui:option[@value='" + code + "']/text()", select);
            assertXpathEvaluatesTo("", "//ui:radiobuttonselect/ui:option[@value='" + code + "']/@isNull", select);
        }
    }
}
Also used : WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Example 20 with WRadioButtonSelect

use of com.github.bordertech.wcomponents.WRadioButtonSelect in project wcomponents by BorderTech.

the class WRadioButtonSelectRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WRadioButtonSelect group = new WRadioButtonSelect(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent() }));
    assertSafeContent(group);
    group.setToolTip(getMaliciousAttribute("ui:radiobuttonselect"));
    assertSafeContent(group);
    group.setAccessibleText(getMaliciousAttribute("ui:radiobuttonselect"));
    assertSafeContent(group);
}
Also used : WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) Test(org.junit.Test)

Aggregations

WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)21 WHeading (com.github.bordertech.wcomponents.WHeading)10 WLabel (com.github.bordertech.wcomponents.WLabel)8 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)8 Test (org.junit.Test)8 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)7 WTextField (com.github.bordertech.wcomponents.WTextField)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)4 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)3 WButton (com.github.bordertech.wcomponents.WButton)3 WPanel (com.github.bordertech.wcomponents.WPanel)3 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WDateField (com.github.bordertech.wcomponents.WDateField)1