Search in sources :

Example 71 with UIContext

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

the class SafetyContainer method handleRequest.

/**
 * Override handleRequest in order to safely process the example component, which has been excluded from normal
 * WComponent processing.
 *
 * @param request the request being responded to.
 */
@Override
public void handleRequest(final Request request) {
    if (!isInitialised()) {
        getOrCreateComponentModel().delegate = new SafetyContainerDelegate(UIContextHolder.getCurrent());
        setInitialised(true);
    }
    try {
        UIContext delegate = getComponentModel().delegate;
        UIContextHolder.pushContext(delegate);
        try {
            for (int i = 0; i < shim.getChildCount(); i++) {
                shim.getChildAt(i).serviceRequest(request);
            }
            delegate.doInvokeLaters();
        } finally {
            UIContextHolder.popContext();
        }
    } catch (final ActionEscape e) {
        // We don't want to catch ActionEscapes (e.g. ForwardExceptions)
        throw e;
    } catch (final Exception e) {
        if (isAjaxOrTargetedRequest(request)) {
            throw new SystemException(e.getMessage(), e);
        } else {
            setAttribute(ERROR_KEY, e);
        }
    }
}
Also used : ActionEscape(com.github.bordertech.wcomponents.ActionEscape) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Example 72 with UIContext

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

the class AutoReFocusExample_Test method testRefocusWDropdown.

@Test
public void testRefocusWDropdown() {
    SeleniumWComponentsWebDriver driver = getDriver();
    String path = "WDropdownSubmitOnChangeExample/WDropdown[0]";
    driver.findWDropdown(byWComponentPath(path)).click();
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    try {
        // The dropdowns in the example need something to be selected to trigger the submit
        WComponent comp = TreeUtil.findWComponent(getUi(), path.split("/")).getComponent();
        if (comp instanceof WDropdown) {
            WDropdown dropdown = (WDropdown) comp;
            driver.findElement(byWComponentPath(path, dropdown.getOptions().get(1))).click();
        }
    } finally {
        UIContextHolder.popContext();
    }
    Assert.assertEquals("Incorrect focus", driver.findWDropdown(byWComponentPath(path)).getActiveId(), driver.switchTo(true).activeElement().getAttribute("id"));
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 73 with UIContext

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

the class AutoReFocusRepeaterExample_Test method testAutoReFocusWDropdowns.

@Test
public void testAutoReFocusWDropdowns() {
    SeleniumWComponentsWebDriver driver = getDriver();
    String[] paths = { ROOT_PATH + "[0]/AutoReFocusExample/WDropdown", ROOT_PATH + "[1]/AutoReFocusExample/WDropdown" };
    for (String path : paths) {
        driver.findWDropdown(byWComponentPath(path)).getInputField().click();
        UIContext uic = getUserContextForSession();
        UIContextHolder.pushContext(uic);
        try {
            // The dropdowns in the example need something to be selected to trigger the submit
            WComponent comp = TreeUtil.findWComponent(getUi(), path.split("/"), false).getComponent();
            if (comp instanceof WDropdown) {
                WDropdown dropdown = (WDropdown) comp;
                driver.findElement(byWComponentPath(path, dropdown.getOptions().get(1))).click();
            }
        } finally {
            UIContextHolder.popContext();
        }
        Assert.assertEquals("Incorrect focus", driver.findWDropdown(byWComponentPath(path)).getActiveId(), driver.switchTo(true).activeElement().getAttribute("id"));
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 74 with UIContext

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

the class WDropdownOptionsExample_Test method testExampleAjax.

/**
 * Ajax test.
 */
@Test
public void testExampleAjax() {
    WDropdownOptionsExample example = (WDropdownOptionsExample) getUi();
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();
    WDropdown.DropdownType type = WDropdown.DropdownType.NATIVE;
    configureDropDown(driver, type, 2);
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    try {
        WDropdown dropdown = (WDropdown) TreeUtil.findWComponent(example, new String[] { "WDropdown" }).getComponent();
        List<?> options = dropdown.getOptions();
        for (Object option : options) {
            driver.findElement(byWComponent(dropdown, option)).click();
            Assert.assertEquals("Incorrect option selected", option, dropdown.getSelected());
            Assert.assertEquals("Incorrect text field text", option, driver.findElement(byWComponentPath("WDropdownOptionsExample/WPanel[1]")).getText());
        }
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 75 with UIContext

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

the class WDropdownSpaceHandlingExample_Test method testDropdown.

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

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