use of com.github.bordertech.wcomponents.WSection in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testRenderedEagerMode.
@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
WSection section = new WSection(SECTION_HEADING);
section.setMode(SectionMode.EAGER);
section.getContent().add(new WText(SECTION_CONTENT));
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The section's content should NOT be rendered
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("eager", "//ui:section/@mode", section);
assertXpathEvaluatesTo("", "normalize-space(//ui:section/ui:panel)", section);
try {
// Section is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(section.getId(), section.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("eager", "//ui:section/@mode", section);
assertXpathEvaluatesTo(SECTION_CONTENT, "normalize-space(//ui:section/ui:panel)", section);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.WSection in project wcomponents by BorderTech.
the class WSectionRenderer method doRender.
/**
* Paints the given WSection.
*
* @param component the WSection to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSection section = (WSection) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean renderChildren = isRenderContent(section);
xml.appendTagOpen("ui:section");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (SectionMode.LAZY.equals(section.getMode())) {
xml.appendOptionalAttribute("hidden", !renderChildren, "true");
} else {
xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
}
SectionMode mode = section.getMode();
if (mode != null) {
switch(mode) {
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
default:
throw new SystemException("Unknown section mode: " + section.getMode());
}
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(section, renderContext);
if (renderChildren) {
// Label
section.getDecoratedLabel().paint(renderContext);
// Content
section.getContent().paint(renderContext);
}
xml.appendEndTag("ui:section");
}
use of com.github.bordertech.wcomponents.WSection in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testRenderedLazyMode.
@Test
public void testRenderedLazyMode() throws IOException, SAXException, XpathException {
WSection section = new WSection(SECTION_HEADING);
section.setMode(SectionMode.LAZY);
section.getContent().add(new WText(SECTION_CONTENT));
// Content NOT Hidden
assertSchemaMatch(section);
// If not hidden, then the section's content should be rendered
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("lazy", "//ui:section/@mode", section);
assertXpathEvaluatesTo(SECTION_CONTENT, "normalize-space(//ui:section/ui:panel)", section);
// Content Hidden
// Create User Context with UI component
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
setFlag(section, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(section);
// If hidden, then the section's content should NOT be rendered
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("true", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("lazy", "//ui:section/@mode", section);
assertXpathEvaluatesTo("", "normalize-space(//ui:section/ui:panel)", section);
}
use of com.github.bordertech.wcomponents.WSection in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testRenderedWithMargins.
@Test
public void testRenderedWithMargins() throws IOException, SAXException, XpathException {
WSection section = new WSection("");
assertXpathNotExists("//ui:section/ui:margin", section);
Margin margin = new Margin(null);
section.setMargin(margin);
assertXpathNotExists("//ui:section/ui:margin", section);
margin = new Margin(Size.SMALL);
section.setMargin(margin);
assertSchemaMatch(section);
assertXpathEvaluatesTo("sm", "//ui:section/ui:margin/@all", section);
assertXpathEvaluatesTo("", "//ui:section/ui:margin/@north", section);
assertXpathEvaluatesTo("", "//ui:section/ui:margin/@east", section);
assertXpathEvaluatesTo("", "//ui:section/ui:margin/@south", section);
assertXpathEvaluatesTo("", "//ui:section/ui:margin/@west", section);
margin = new Margin(Size.SMALL, Size.MEDIUM, Size.LARGE, Size.XL);
section.setMargin(margin);
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/ui:margin/@all", section);
assertXpathEvaluatesTo("sm", "//ui:section/ui:margin/@north", section);
assertXpathEvaluatesTo("med", "//ui:section/ui:margin/@east", section);
assertXpathEvaluatesTo("lg", "//ui:section/ui:margin/@south", section);
assertXpathEvaluatesTo("xl", "//ui:section/ui:margin/@west", section);
}
use of com.github.bordertech.wcomponents.WSection in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WSection section = new WSection(getMaliciousContent());
section.getContent().add(new WText(getMaliciousContent()));
assertSafeContent(section);
}
Aggregations