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);
}
}
}
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"));
}
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"));
}
}
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();
}
}
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();
}
}
Aggregations