Search in sources :

Example 76 with UIContext

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

the class WDropdownSpaceHandlingExample_Test method testCheckbox.

@Test
public void testCheckbox() {
    WDropdownSpaceHandlingExample example = (WDropdownSpaceHandlingExample) getUi();
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    try {
        WCheckBoxSelect group = (WCheckBoxSelect) TreeUtil.findWComponent(example, new String[] { "WCheckBoxSelect" }).getComponent();
        List<?> options = group.getOptions();
        for (Object option : options) {
            driver.findElement(byWComponent(group, option)).click();
            driver.findElement(byWComponentPath("WButton")).click();
            Assert.assertEquals("Incorrect option selected", option, group.getSelected().get(0));
            // De-select option
            driver.findElement(byWComponent(group, option)).click();
        }
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) UIContext(com.github.bordertech.wcomponents.UIContext) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) Test(org.junit.Test)

Example 77 with UIContext

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

the class WServlet_Test method testServiceNormalRequest.

@Test
public void testServiceNormalRequest() throws ServletException, IOException {
    MockServletConfig config = new MockServletConfig();
    config.setInitParameter(WServlet.WServletHelper.ONGOING_URL_SUFFIX, "foo");
    MockContainer content = new MockContainer();
    content.add(new WText(LABEL_TEXT));
    content.setLocked(true);
    MyWServlet servlet = new MyWServlet(content);
    servlet.init(config);
    MockHttpSession session1 = new MockHttpSession();
    MockHttpSession session2 = new MockHttpSession();
    sendRequest(session1, servlet);
    sendRequest(session2, servlet);
    sendRequest(session1, servlet);
    // check handle request / paint counts for each session
    UIContext uic = getContextForSession(servlet, session1);
    setActiveContext(uic);
    Assert.assertEquals("Incorrect handle request count for session1", 2, content.getHandleRequestCount());
    Assert.assertEquals("Incorrect paint count for session1", 2, content.getPaintCount());
    uic = getContextForSession(servlet, session2);
    setActiveContext(uic);
    Assert.assertEquals("Incorrect handle request count for session2", 1, content.getHandleRequestCount());
    Assert.assertEquals("Incorrect paint count for session2", 1, content.getPaintCount());
}
Also used : MockContainer(com.github.bordertech.wcomponents.MockContainer) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 78 with UIContext

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

the class AjaxInterceptor method isProcessTriggerOnly.

/**
 * Check if process this trigger only.
 *
 * @param triggerWithContext the trigger with its context
 * @param operation current ajax operation
 * @return true if process this trigger only
 */
private boolean isProcessTriggerOnly(final ComponentWithContext triggerWithContext, final AjaxOperation operation) {
    // Target container implies only process the trigger or is Internal Ajax
    if (operation.getTargetContainerId() != null || operation.isInternalAjaxRequest()) {
        return true;
    }
    WComponent trigger = triggerWithContext.getComponent();
    // Check if trigger is a polling AJAX control
    if (trigger instanceof WAjaxControl) {
        // Get user context
        UIContext uic = triggerWithContext.getContext();
        UIContextHolder.pushContext(uic);
        try {
            WAjaxControl ajax = (WAjaxControl) trigger;
            // Is a polling region so only process trigger
            if (ajax.getDelay() > 0) {
                return true;
            }
        } finally {
            UIContextHolder.popContext();
        }
    }
    return false;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) UIContext(com.github.bordertech.wcomponents.UIContext)

Example 79 with UIContext

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

the class AjaxPageShellInterceptor method paint.

/**
 * Paints the targeted ajax regions. The format of the response is an agreement between the server and the client
 * side handling our AJAX response.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
    XmlStringBuilder xml = webRenderContext.getWriter();
    AjaxOperation operation = AjaxHelper.getCurrentOperation();
    if (operation == null) {
        // the request attribute that we place in the ui contenxt in the action phase can't be null
        throw new SystemException("Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation.");
    }
    UIContext uic = UIContextHolder.getCurrent();
    String focusId = uic.getFocussedId();
    xml.append(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
    xml.appendTagOpen("ui:ajaxresponse");
    xml.append(XMLUtil.STANDARD_NAMESPACES);
    xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
    xml.appendClose();
    getBackingComponent().paint(renderContext);
    xml.appendEndTag("ui:ajaxresponse");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 80 with UIContext

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

the class ContextCleanupInterceptor method serviceRequest.

/**
 * Override serviceRequest to clear out the targetable index from the last request. And clear out the scratch map
 * after the request has been processed (and before painting occurs).
 *
 * @param request the request being responded to.
 */
@Override
public void serviceRequest(final Request request) {
    LOG.debug("Before Service Request - Clearing targetable index.");
    UIContext uic = UIContextHolder.getCurrent();
    super.serviceRequest(request);
    // Clear phase scope scratch map
    LOG.debug("After Service Request - Clearing scratch map with phase scope.");
    uic.clearScratchMap();
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

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