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