Search in sources :

Example 6 with WRadioButton

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

the class WRadioButtonRenderer_Test method testIsNullOption.

@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
    WPanel root = new WPanel();
    RadioButtonGroup group = new RadioButtonGroup();
    root.add(group);
    WRadioButton button1 = group.addRadioButton(null);
    WRadioButton button2 = group.addRadioButton("");
    WRadioButton button3 = group.addRadioButton("A");
    root.add(button1);
    root.add(button2);
    root.add(button3);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@isNull", button1);
    assertXpathEvaluatesTo("true", "//ui:radiobutton/@isNull", button2);
    assertXpathEvaluatesTo("", "//ui:radiobutton/@isNull", button3);
}
Also used : WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WPanel(com.github.bordertech.wcomponents.WPanel) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) Test(org.junit.Test)

Example 7 with WRadioButton

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

the class WLabelRenderer method doRender.

/**
 * Paints the given {@link WLabel}.
 *
 * @param component the WLabel to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WLabel label = (WLabel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:label");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("for", label.getLabelFor());
    WComponent what = label.getForComponent();
    String whatFor = null;
    if (what instanceof MultiInputComponent) {
        whatFor = "group";
    } else if (what instanceof Labelable) {
        whatFor = "input";
    }
    boolean isReadOnly = ((what instanceof Input) && ((Input) what).isReadOnly()) || (what instanceof WRadioButton && ((WRadioButton) what).isReadOnly());
    boolean isMandatory = (what instanceof Input) && ((Input) what).isMandatory();
    xml.appendOptionalAttribute("what", whatFor);
    xml.appendOptionalAttribute("readonly", isReadOnly, "true");
    xml.appendOptionalAttribute("required", isMandatory, "true");
    xml.appendOptionalAttribute("hiddencomponent", (what != null && what.isHidden()), "true");
    xml.appendOptionalAttribute("hint", label.getHint());
    xml.appendOptionalAttribute("accessKey", Util.upperCase(label.getAccessKeyAsString()));
    xml.appendOptionalAttribute("hidden", label.isHidden(), "true");
    xml.appendOptionalAttribute("toolTip", label.getToolTip());
    xml.appendOptionalAttribute("accessibleText", label.getAccessibleText());
    xml.appendClose();
    xml.append(label.getText(), label.isEncodeText());
    paintChildren(label, renderContext);
    xml.appendEndTag("ui:label");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Labelable(com.github.bordertech.wcomponents.Labelable) MultiInputComponent(com.github.bordertech.wcomponents.MultiInputComponent) Input(com.github.bordertech.wcomponents.Input) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 8 with WRadioButton

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

the class WRadioButtonRenderer method doRender.

/**
 * Paints the given WRadioButton.
 *
 * @param component the WRadioButton to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WRadioButton button = (WRadioButton) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = button.isReadOnly();
    String value = button.getValue();
    xml.appendTagOpen("ui:radiobutton");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", button.isHidden(), "true");
    xml.appendAttribute("groupName", button.getGroupName());
    xml.appendAttribute("value", WebUtilities.encode(value));
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("disabled", button.isDisabled(), "true");
        xml.appendOptionalAttribute("required", button.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", button.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", button.getToolTip());
        xml.appendOptionalAttribute("accessibleText", button.getAccessibleText());
        // Check for null option (ie null or empty). Match isEmpty() logic.
        boolean isNull = value == null ? true : (value.length() == 0);
        xml.appendOptionalAttribute("isNull", isNull, "true");
    }
    xml.appendOptionalAttribute("selected", button.isSelected(), "true");
    xml.appendEnd();
}
Also used : WRadioButton(com.github.bordertech.wcomponents.WRadioButton) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 9 with WRadioButton

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

the class WRadioButtonRenderer_Test method testRendererCorrectlyConfigured.

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

Example 10 with WRadioButton

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

the class WRadioButtonRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    RadioButtonGroup group = new RadioButtonGroup();
    WRadioButton button = group.addRadioButton(1);
    assertSafeContent(button);
    button.setToolTip(getMaliciousAttribute());
    assertSafeContent(button);
    button.setAccessibleText(getMaliciousAttribute());
    assertSafeContent(button);
}
Also used : WRadioButton(com.github.bordertech.wcomponents.WRadioButton) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) Test(org.junit.Test)

Aggregations

WRadioButton (com.github.bordertech.wcomponents.WRadioButton)12 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)9 Test (org.junit.Test)6 WLabel (com.github.bordertech.wcomponents.WLabel)3 AbstractWSelectList (com.github.bordertech.wcomponents.AbstractWSelectList)2 WDateField (com.github.bordertech.wcomponents.WDateField)2 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2 WNumberField (com.github.bordertech.wcomponents.WNumberField)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)2 Input (com.github.bordertech.wcomponents.Input)1 Labelable (com.github.bordertech.wcomponents.Labelable)1 Margin (com.github.bordertech.wcomponents.Margin)1 MultiInputComponent (com.github.bordertech.wcomponents.MultiInputComponent)1 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WContainer (com.github.bordertech.wcomponents.WContainer)1