Search in sources :

Example 1 with WSection

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();
    }
}
Also used : WSection(com.github.bordertech.wcomponents.WSection) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 2 with WSection

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");
}
Also used : WSection(com.github.bordertech.wcomponents.WSection) SectionMode(com.github.bordertech.wcomponents.WSection.SectionMode) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WSection

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);
}
Also used : WSection(com.github.bordertech.wcomponents.WSection) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 4 with WSection

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);
}
Also used : WSection(com.github.bordertech.wcomponents.WSection) Margin(com.github.bordertech.wcomponents.Margin) Test(org.junit.Test)

Example 5 with WSection

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);
}
Also used : WSection(com.github.bordertech.wcomponents.WSection) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Aggregations

WSection (com.github.bordertech.wcomponents.WSection)6 Test (org.junit.Test)5 WText (com.github.bordertech.wcomponents.WText)3 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 UIContext (com.github.bordertech.wcomponents.UIContext)2 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)1 Margin (com.github.bordertech.wcomponents.Margin)1 SectionMode (com.github.bordertech.wcomponents.WSection.SectionMode)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1