Search in sources :

Example 16 with UIContext

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

the class WDropdownTriggerActionExample_Test method testExample.

@Test
public void testExample() {
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();
    WDropdownTriggerActionExample ui = (WDropdownTriggerActionExample) getUi();
    // Select "ACT" from State dropdown
    driver.findElement(byWComponent(ui.getStateDropdown(), "ACT")).click();
    Assert.assertTrue("Incorrect region selection on client", driver.findElement(byWComponent(ui.getRegionDropdown(), "")).isSelected());
    // Context is required for in-JVM calls to work.
    // This is generally not a good test, as it relies on the JVM not on the servlet.
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    // Should have round-tripped, check server and client-side states
    Assert.assertEquals("Incorrect state selection on server", "ACT", ui.getStateDropdown().getSelected());
    Assert.assertTrue("Incorrect state selection on client", driver.findElement(byWComponent(ui.getStateDropdown(), "ACT")).isSelected());
    // Select "Woden" from Region dropdown
    driver.findElement(byWComponent(ui.getRegionDropdown(), "Woden")).click();
    // Should have round-tripped, check server and client-side states
    Assert.assertEquals("Incorrect region selection on server", "Woden", ui.getRegionDropdown().getSelected());
    Assert.assertTrue("Incorrect region selection on client", driver.findElement(byWComponent(ui.getRegionDropdown(), "Woden")).isSelected());
    // Select "Torrens" from Suburb dropdown (no round trip)
    driver.findElement(byWComponent(ui.getSuburbDropdown(), "Torrens")).click();
    Assert.assertTrue("Incorrect suburb selection on client", driver.findElement(byWComponent(ui.getSuburbDropdown(), "Torrens")).isSelected());
    // Select "VIC" from the State dropdown
    driver.findElement(byWComponent(ui.getStateDropdown(), "VIC")).click();
    Assert.assertTrue("Incorrect region selection on client", driver.findElement(byWComponent(ui.getRegionDropdown(), "")).isSelected());
    // Select "Melbourne" from Region dropdown
    driver.findElement(byWComponent(ui.getRegionDropdown(), "Melbourne")).click();
    // Select "Torrens" from Suburb dropdown (no round trip)
    driver.findElement(byWComponent(ui.getSuburbDropdown(), "Blackburn")).click();
    Assert.assertTrue("Incorrect suburb selection on client", driver.findElement(byWComponent(ui.getSuburbDropdown(), "Blackburn")).isSelected());
    UIContextHolder.popContext();
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 17 with UIContext

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

the class WListRenderer method paintRows.

/**
 * Paints the rows.
 *
 * @param list the WList to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
protected void paintRows(final WList list, final WebXmlRenderContext renderContext) {
    List<?> beanList = list.getBeanList();
    WComponent row = list.getRepeatedComponent();
    XmlStringBuilder xml = renderContext.getWriter();
    for (int i = 0; i < beanList.size(); i++) {
        Object rowData = beanList.get(i);
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = list.getRowContext(rowData, i);
        UIContextHolder.pushContext(rowContext);
        try {
            xml.appendTag("ui:cell");
            row.paint(renderContext);
            xml.appendEndTag("ui:cell");
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 18 with UIContext

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

the class WTableRenderer method doPaintRows.

/**
 * Override paintRow so that we only paint the first-level nodes for tree-tables.
 *
 * @param table the table to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
private void doPaintRows(final WTable table, final WebXmlRenderContext renderContext) {
    TableRepeater repeater = table.getRepeater();
    WComponent row = repeater.getRepeatedComponent();
    List<RowIdWrapper> wrappers = repeater.getBeanList();
    Set<?> otherSelectedRows = new HashSet<>(table.getSelectedRows());
    int index = -1;
    for (RowIdWrapper wrapper : wrappers) {
        index++;
        Object rowKey = wrapper.getRowKey();
        if (table.getSelectedRows().contains(rowKey)) {
            otherSelectedRows.remove(rowKey);
        }
        // Child rows handled by the layout, so dont paint the row
        if (wrapper.getParent() != null) {
            continue;
        }
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = repeater.getRowContext(wrapper, index);
        UIContextHolder.pushContext(rowContext);
        try {
            row.paint(renderContext);
        } finally {
            UIContextHolder.popContext();
        }
    }
    this.selectedOnOther = otherSelectedRows.size();
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) TableRepeater(com.github.bordertech.wcomponents.WTable.TableRepeater) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) UIContext(com.github.bordertech.wcomponents.UIContext) HashSet(java.util.HashSet)

Example 19 with UIContext

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

the class WTableRowRendererRenderer method renderChildren.

/**
 * @param renderer the WTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 * @param children the children ids
 */
private void renderChildren(final WTableRowRenderer renderer, final WebXmlRenderContext renderContext, final List<RowIdWrapper> children) {
    XmlStringBuilder xml = renderContext.getWriter();
    WTable table = renderer.getTable();
    WRepeater repeater = table.getRepeater();
    TableModel dataModel = table.getTableModel();
    // If there is a renderer specified by any child, we only paint content that has a specified renderer
    boolean rendererPresent = false;
    for (RowIdWrapper child : children) {
        if (dataModel.getRendererClass(child.getRowIndex()) != null) {
            rendererPresent = true;
            break;
        }
    }
    // Paint immediate children only.
    if (rendererPresent) {
        xml.appendTagOpen("ui:content");
        // Always span all columns
        xml.appendAttribute("spanAllCols", "true");
        xml.appendClose();
        for (RowIdWrapper child : children) {
            UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
            WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(dataModel.getRendererClass(child.getRowIndex()));
            if (expandedRenderer != null) {
                UIContextHolder.pushContext(nodeContext);
                try {
                    expandedRenderer.paint(renderContext);
                } finally {
                    UIContextHolder.popContext();
                }
            }
        }
        xml.appendEndTag("ui:content");
    } else {
        for (RowIdWrapper child : children) {
            UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
            UIContextHolder.pushContext(nodeContext);
            try {
                render(renderer, renderContext);
            } finally {
                UIContextHolder.popContext();
            }
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) WTable(com.github.bordertech.wcomponents.WTable) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WRepeater(com.github.bordertech.wcomponents.WRepeater) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 20 with UIContext

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

the class DebugStructureInterceptor_Test method doRequest.

/**
 * Does a request/response cycle for a WApplication.
 *
 * @return the xml output.
 */
private String doRequest() {
    WApplication app = new WApplication();
    app.setLocked(true);
    UIContext uic = createUIContext();
    uic.setUI(app);
    setActiveContext(uic);
    // Create interceptor
    PageShellInterceptor pageInterceptor = new PageShellInterceptor();
    DebugStructureInterceptor debugInterceptor = new DebugStructureInterceptor();
    pageInterceptor.setBackingComponent(debugInterceptor);
    pageInterceptor.attachUI(app);
    // Action phase
    MockRequest request = new MockRequest();
    pageInterceptor.serviceRequest(request);
    pageInterceptor.preparePaint(request);
    // Render phase
    MockResponse response = new MockResponse();
    pageInterceptor.attachResponse(response);
    pageInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
    return response.getWriterOutput();
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest)

Aggregations

UIContext (com.github.bordertech.wcomponents.UIContext)114 Test (org.junit.Test)47 WComponent (com.github.bordertech.wcomponents.WComponent)18 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)15 SystemException (com.github.bordertech.wcomponents.util.SystemException)14 WApplication (com.github.bordertech.wcomponents.WApplication)13 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)11 WText (com.github.bordertech.wcomponents.WText)11 PrintWriter (java.io.PrintWriter)11 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)9 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)7 WDropdown (com.github.bordertech.wcomponents.WDropdown)7 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)7 StringWriter (java.io.StringWriter)7 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)6 Environment (com.github.bordertech.wcomponents.Environment)6 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)6