Search in sources :

Example 1 with AjaxOperation

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

the class WSuggestionsRenderer_Test method testDoPaintAjaxOptions.

@Test
public void testDoPaintAjaxOptions() throws IOException, SAXException, XpathException {
    List<String> options = Arrays.asList("A", "B", "C");
    WSuggestions field = new WSuggestions(options);
    // Set action for AJAX refresh
    field.setRefreshAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // Do nothing
        }
    });
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/@data", field);
    // AJAX flag should be true
    assertXpathEvaluatesTo("true", "//ui:suggestions/@ajax", field);
    // Suggestions should only be rendered when refreshed via AJAX
    assertXpathNotExists("//ui:suggestions/ui:suggestion", field);
    // Setup suggestions as the current AJAX trigger
    UIContext uic = createUIContext();
    uic.setUI(new DefaultWComponent());
    setActiveContext(uic);
    try {
        AjaxOperation operation = new AjaxOperation(field.getId(), field.getId());
        AjaxHelper.setCurrentOperationDetails(operation, null);
        assertSchemaMatch(field);
        assertXpathExists("//ui:suggestions/ui:suggestion", field);
        assertXpathEvaluatesTo(options.get(0), "//ui:suggestions/ui:suggestion[1]/@value", field);
        assertXpathEvaluatesTo(options.get(1), "//ui:suggestions/ui:suggestion[2]/@value", field);
        assertXpathEvaluatesTo(options.get(2), "//ui:suggestions/ui:suggestion[3]/@value", field);
    } finally {
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : Action(com.github.bordertech.wcomponents.Action) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) UIContext(com.github.bordertech.wcomponents.UIContext) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 2 with AjaxOperation

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

the class WFigureRenderer_Test method testRenderedEagerMode.

@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
    WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
    figure.setMode(FigureMode.EAGER);
    UIContext uic = createUIContext();
    uic.setUI(new DefaultWComponent());
    setActiveContext(uic);
    // The figure's content should NOT be rendered
    assertSchemaMatch(figure);
    assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
    assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
    assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
    assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure);
    try {
        // Figure is the AJAX Trigger, content should be rendered
        AjaxOperation operation = new AjaxOperation(figure.getId(), figure.getId());
        AjaxHelper.setCurrentOperationDetails(operation, null);
        assertSchemaMatch(figure);
        assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
        assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
        assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
        assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure);
    } finally {
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) 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 3 with AjaxOperation

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

the class WPanelRenderer_Test method testRenderedEagerModePanel.

@Test
public void testRenderedEagerModePanel() throws IOException, SAXException, XpathException {
    String content = "TEST CONTENT";
    WPanel panel = new WPanel();
    panel.setMode(PanelMode.EAGER);
    panel.add(new WText(content));
    UIContext uic = createUIContext();
    uic.setUI(new DefaultWComponent());
    setActiveContext(uic);
    // The panel's content should NOT be rendered
    assertSchemaMatch(panel);
    assertXpathEvaluatesTo("", "//ui:panel/@type", panel);
    assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel);
    assertXpathEvaluatesTo("eager", "//ui:panel/@mode", panel);
    assertXpathEvaluatesTo("", "//ui:panel/ui:content", panel);
    try {
        // Panel is the AJAX Trigger, content should be rendered
        AjaxOperation operation = new AjaxOperation(panel.getId(), panel.getId());
        AjaxHelper.setCurrentOperationDetails(operation, null);
        assertSchemaMatch(panel);
        assertXpathEvaluatesTo("", "//ui:panel/@type", panel);
        assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel);
        assertXpathEvaluatesTo("eager", "//ui:panel/@mode", panel);
        assertXpathEvaluatesTo(content, "//ui:panel/ui:content", panel);
    } finally {
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) WPanel(com.github.bordertech.wcomponents.WPanel) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 4 with AjaxOperation

use of com.github.bordertech.wcomponents.AjaxOperation 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 5 with AjaxOperation

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

the class AjaxDebugStructureInterceptor method paint.

/**
 * Override paint to only output the debugging info for the current targets.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    if (!DebugUtil.isDebugFeaturesEnabled() || !(renderContext instanceof WebXmlRenderContext)) {
        getBackingComponent().paint(renderContext);
        return;
    }
    AjaxOperation operation = AjaxHelper.getCurrentOperation();
    if (operation == null) {
        getBackingComponent().paint(renderContext);
        return;
    }
    getBackingComponent().paint(renderContext);
    XmlStringBuilder xml = ((WebXmlRenderContext) renderContext).getWriter();
    xml.appendTag("ui:debug");
    for (String targetId : operation.getTargets()) {
        ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
        if (target != null) {
            writeDebugInfo(target.getComponent(), xml);
        }
    }
    xml.appendEndTag("ui:debug");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Aggregations

AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)8 UIContext (com.github.bordertech.wcomponents.UIContext)6 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)4 Test (org.junit.Test)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 WText (com.github.bordertech.wcomponents.WText)3 WComponent (com.github.bordertech.wcomponents.WComponent)2 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)2 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 AjaxInternalTrigger (com.github.bordertech.wcomponents.AjaxInternalTrigger)1 WFigure (com.github.bordertech.wcomponents.WFigure)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 WSection (com.github.bordertech.wcomponents.WSection)1 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)1