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