Search in sources :

Example 1 with Environment

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

the class AbstractContainerHelper method render.

/**
 * Support standard processing of the render phase of a request.
 *
 * @throws IOException IO Exception
 */
public void render() throws IOException {
    if (isDisposed()) {
        LOG.debug("Skipping render phase.");
        return;
    }
    try {
        // Check user context has been prepared
        if (getNewConversation() == null) {
            throw new IllegalStateException("User context has not been prepared before the render phase");
        }
        prepareRender();
        UIContext uic = getUIContext();
        if (uic == null) {
            throw new IllegalStateException("No user context set for the render phase.");
        }
        UIContextHolder.pushContext(uic);
        prepareRequest();
        // Handle errors from the action phase now.
        if (havePropogatedError()) {
            handleError(getPropogatedError());
            return;
        }
        WComponent uiComponent = getUI();
        if (uiComponent == null) {
            throw new SystemException("No UI Component exists.");
        }
        Environment environment = uiComponent.getEnvironment();
        if (environment == null) {
            throw new SystemException("No WEnvironment exists.");
        }
        getInterceptor().attachResponse(getResponse());
        getInterceptor().preparePaint(getRequest());
        String contentType = getUI().getHeaders().getContentType();
        Response response = getResponse();
        response.setContentType(contentType);
        addGenericHeaders(uic, getUI());
        PrintWriter writer = getPrintWriter();
        getInterceptor().paint(new WebXmlRenderContext(writer, uic.getLocale()));
        // The following only matters for a Portal context
        String title = uiComponent instanceof WApplication ? ((WApplication) uiComponent).getTitle() : null;
        if (title != null) {
            setTitle(title);
        }
    } catch (Escape esc) {
        LOG.debug("Escape performed during render phase.");
        handleEscape(esc);
    } catch (Throwable t) {
        // We try not to let any exception propagate to container.
        String message = "Caught exception during render phase.";
        LOG.error(message, t);
        handleError(t);
    } finally {
        UIContextHolder.reset();
        dispose();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Response(com.github.bordertech.wcomponents.Response) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) Escape(com.github.bordertech.wcomponents.Escape) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) WApplication(com.github.bordertech.wcomponents.WApplication) Environment(com.github.bordertech.wcomponents.Environment) PrintWriter(java.io.PrintWriter)

Example 2 with Environment

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

the class AbstractContainerHelper method prepareRequest.

/**
 * Prepare the session for the current request.
 */
protected void prepareRequest() {
    LOG.debug("Preparing for request by adding headers and environment to top wcomponent");
    // Configure the UIContext to handle this request.
    UIContext uiContext = getUIContext();
    // Add WEnvironment if not already done.
    // If the component is new, then it will not have a WEnvironment yet.
    Environment env;
    if (uiContext.isDummyEnvironment()) {
        env = createEnvironment();
        uiContext.setEnvironment(env);
    } else {
        env = uiContext.getEnvironment();
    }
    // Update the environment for the current phase of the request
    // processing.
    updateEnvironment(env);
    // container we are running in.
    if (getRequest() == null) {
        setRequest(createRequest());
    }
    // Update the wcomponent Request for the current phase of the request
    // processing.
    updateRequest(getRequest());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment)

Example 3 with Environment

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

the class InfoDump_Test method testExample.

@Test
public void testExample() {
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();
    Assert.assertEquals("Incorrect default text", "", driver.findWTextArea(byWComponentPath("WTextArea")).getText());
    driver.findElement(byWComponentPath("WButton[1]")).click();
    String text = driver.findWTextArea(byWComponentPath("WTextArea")).getText();
    Assert.assertTrue("Text should contain dump info", text.contains("WEnvironment"));
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    try {
        Environment env = getUi().getEnvironment();
        Assert.assertTrue("Incorrect AppId", text.contains("AppId: " + env.getAppId()));
    } finally {
        UIContextHolder.popContext();
    }
    driver.findElement(byWComponentPath("WButton[0]")).click();
    Assert.assertEquals("Text should have been cleared", "", driver.findWTextArea(byWComponentPath("WTextArea")).getText());
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment) Test(org.junit.Test)

Example 4 with Environment

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

the class WWindowInterceptor method preparePaint.

/**
 * Temporarily replaces the environment while the UI prepares to render.
 *
 * @param request the request being responded to.
 */
@Override
public void preparePaint(final Request request) {
    if (windowId == null) {
        super.preparePaint(request);
    } else {
        // Get the window component
        ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
        if (target == null) {
            throw new SystemException("No window component for id " + windowId);
        }
        UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
        Environment originalEnvironment = uic.getEnvironment();
        uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
        UIContextHolder.pushContext(target.getContext());
        try {
            super.preparePaint(request);
        } finally {
            uic.setEnvironment(originalEnvironment);
            UIContextHolder.popContext();
        }
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 5 with Environment

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

the class WWindowInterceptor method paint.

/**
 * Temporarily replaces the environment while the UI is being rendered.
 *
 * @param renderContext the context to render to.
 */
@Override
public void paint(final RenderContext renderContext) {
    if (windowId == null) {
        super.paint(renderContext);
    } else {
        // Get the window component
        ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
        if (target == null) {
            throw new SystemException("No window component for id " + windowId);
        }
        UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
        Environment originalEnvironment = uic.getEnvironment();
        uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
        UIContextHolder.pushContext(target.getContext());
        try {
            super.paint(renderContext);
        } finally {
            uic.setEnvironment(originalEnvironment);
            UIContextHolder.popContext();
        }
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Aggregations

Environment (com.github.bordertech.wcomponents.Environment)7 UIContext (com.github.bordertech.wcomponents.UIContext)6 SystemException (com.github.bordertech.wcomponents.util.SystemException)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)1 Escape (com.github.bordertech.wcomponents.Escape)1 Response (com.github.bordertech.wcomponents.Response)1 WApplication (com.github.bordertech.wcomponents.WApplication)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)1 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)1 PrintWriter (java.io.PrintWriter)1 Test (org.junit.Test)1