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);
}
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");
}
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();
}
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);
}
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);
}
Aggregations