use of com.github.bordertech.wcomponents.WSelectToggle in project wcomponents by BorderTech.
the class WSelectToggleRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
// Client-side
WCheckBox target = new WCheckBox();
WSelectToggle toggle = new WSelectToggle(true);
toggle.setTarget(target);
WContainer root = new WContainer();
root.add(toggle);
root.add(target);
assertSchemaMatch(toggle);
assertXpathNotExists("//ui:selecttoggle/@roundTrip", toggle);
assertXpathEvaluatesTo(toggle.getId(), "//ui:selecttoggle/@id", toggle);
assertXpathEvaluatesTo(toggle.getTarget().getId(), "//ui:selecttoggle/@target", toggle);
assertXpathEvaluatesTo("control", "//ui:selecttoggle/@renderAs", toggle);
assertXpathEvaluatesTo("none", "//ui:selecttoggle/@selected", toggle);
// Test Server-side
toggle.setClientSide(false);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:selecttoggle/@roundTrip", toggle);
// Test when selected
toggle.setState(WSelectToggle.State.ALL);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("all", "//ui:selecttoggle/@selected", toggle);
// Test when partially selected
toggle.setState(WSelectToggle.State.SOME);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("some", "//ui:selecttoggle/@selected", toggle);
}
use of com.github.bordertech.wcomponents.WSelectToggle in project wcomponents by BorderTech.
the class WSelectToggleRenderer method doRender.
/**
* Paints the given WSelectToggle.
*
* @param component the WSelectToggle to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSelectToggle toggle = (WSelectToggle) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:selecttoggle");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
State state = toggle.getState();
if (State.ALL.equals(state)) {
xml.appendAttribute("selected", "all");
} else if (State.NONE.equals(state)) {
xml.appendAttribute("selected", "none");
} else {
xml.appendAttribute("selected", "some");
}
xml.appendOptionalAttribute("disabled", toggle.isDisabled(), "true");
xml.appendAttribute("target", toggle.getTarget().getId());
xml.appendAttribute("renderAs", toggle.isRenderAsText() ? "text" : "control");
xml.appendOptionalAttribute("roundTrip", !toggle.isClientSide(), "true");
xml.appendEnd();
}
use of com.github.bordertech.wcomponents.WSelectToggle in project wcomponents by BorderTech.
the class WSelectToggleRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WSelectToggle component = new WSelectToggle();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WSelectToggleRenderer);
}
Aggregations