Search in sources :

Example 31 with UIContext

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

the class ContextCleanupInterceptor method paint.

/**
 * Override paint to clear out the scratch map and component models which are no longer necessary.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    super.paint(renderContext);
    UIContext uic = UIContextHolder.getCurrent();
    if (LOG.isDebugEnabled()) {
        UIContextDebugWrapper debugWrapper = new UIContextDebugWrapper(uic);
        LOG.debug("Session usage after paint:\n" + debugWrapper);
    }
    LOG.debug("Performing session tidy up of WComponents (any WComponents disconnected from the active top component will not be tidied up.");
    getUI().tidyUpUIContextForTree();
    LOG.debug("After paint - Clearing scratch maps.");
    uic.clearScratchMap();
    uic.clearRequestScratchMap();
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextDebugWrapper(com.github.bordertech.wcomponents.UIContextDebugWrapper)

Example 32 with UIContext

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

the class DefaultPageShell method writeHeader.

/**
 * {@inheritDoc}
 */
@Override
public void writeHeader(final PrintWriter writer) {
    UIContext uic = UIContextHolder.getCurrent();
    addHeadlines(writer, uic.getHeaders().getHeadLines());
    addJsHeadlines(writer, uic.getHeaders().getHeadLines(Headers.JAVASCRIPT_HEADLINE));
    addCssHeadlines(writer, uic.getHeaders().getHeadLines(Headers.CSS_HEADLINE));
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

Example 33 with UIContext

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

the class FormInterceptor method paint.

/**
 * Override paint in order to perform processing specific to this interceptor.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    getBackingComponent().paint(renderContext);
    // We don't want to remember the focus for the next render because on
    // a multi portlet page, we'd end up with multiple portlets trying to
    // set the focus.
    UIContext uic = UIContextHolder.getCurrent();
    if (uic.isFocusRequired()) {
        boolean sticky = ConfigurationProperties.getStickyFocus();
        if (!sticky) {
            uic.setFocussed(null, null);
            uic.setFocusRequired(false);
        }
    }
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

Example 34 with UIContext

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

the class SessionTokenAjaxInterceptor method serviceRequest.

/**
 * Override to check whether the session token variable in the incoming request matches what we expect.
 *
 * @param request the request being serviced.
 */
@Override
public void serviceRequest(final Request request) {
    // Get the expected session token
    UIContext uic = UIContextHolder.getCurrent();
    String expected = uic.getEnvironment().getSessionToken();
    // Session token should already be set
    if (expected == null) {
        LOG.error("Session token should already be set on the session before AJAX request. Can be due to the session timing out.");
        handleError();
    }
    // Get the session token from the request
    String got = request.getParameter(Environment.SESSION_TOKEN_VARIABLE);
    // Check tokens match (both must be provided)
    if (Util.equals(expected, got)) {
        // Process Service Request
        getBackingComponent().serviceRequest(request);
    } else {
        // Invalid token
        LOG.error("Wrong session token detected for AJAX request. Expected token [" + expected + "] but got token [" + got + "].");
        handleError();
    }
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

Example 35 with UIContext

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

the class SessionTokenContentInterceptor method serviceRequest.

/**
 * Override to check whether the session token variable in the incoming request matches what we expect.
 *
 * @param request the request being serviced.
 */
@Override
public void serviceRequest(final Request request) {
    // Get the expected session token
    UIContext uic = UIContextHolder.getCurrent();
    String expected = uic.getEnvironment().getSessionToken();
    // Session token should already be set
    if (expected == null) {
        LOG.error("Session token should already be set on the session before content request. Can be due to the session timing out.");
        handleError();
    }
    // Get the session token from the request
    String got = request.getParameter(Environment.SESSION_TOKEN_VARIABLE);
    // Check tokens match (both must be provided)
    if (Util.equals(expected, got)) {
        // Process Service Request
        getBackingComponent().serviceRequest(request);
    } else if (got == null && StepCountUtil.isCachedContentRequest(request)) {
        // Check cached content (no session token on request)
        // Process Service Request
        getBackingComponent().serviceRequest(request);
    } else {
        // Invalid token
        // Set an error code
        LOG.warn("Wrong session token detected for content request. Expected token [" + expected + "] but got token [" + got + "].");
        handleError();
    }
}
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