Search in sources :

Example 1 with WApplication

use of com.github.bordertech.wcomponents.WApplication 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 WApplication

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

the class DynamicLauncher method setComponentToLaunch.

/**
 * <p>
 * Set the instance for the UI to launch.</p>
 * <p>
 * A null value will revert to the Default PlainLauncher parameter behavior.
 * </p>
 *
 * @param uniqueId the uniqueId to register the component.
 * @param componentToLaunch the WComponent to launch.
 * @return the registered component as a singleton.
 */
public WApplication setComponentToLaunch(final String uniqueId, final WApplication componentToLaunch) {
    setCurrentKey(uniqueId);
    // Check if already registered
    WApplication appl = getRegisteredComponent(uniqueId);
    if (appl != null) {
        return appl;
    }
    // Register the componenent
    registerComponent(uniqueId, componentToLaunch);
    return componentToLaunch;
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication)

Example 3 with WApplication

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

the class SimplePicker method updateTitle.

/**
 * Updates the title, based on the selected example.
 */
private void updateTitle() {
    String title;
    if (this.getCurrentComponent() == null) {
        title = "Example Picker";
    } else {
        title = this.getCurrentComponent().getClass().getName();
    }
    WApplication app = WebUtilities.getAncestorOfClass(WApplication.class, this);
    if (app != null) {
        app.setTitle(title);
    }
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication)

Example 4 with WApplication

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

the class TreeUtil_Test method initTree.

@Before
public void initTree() {
    root = new WApplication();
    containerChild = new WContainer();
    simpleChild = new WTextField();
    repeatedComponent = new WText();
    repeaterChild = new WRepeater(repeatedComponent);
    grandChild = new WTextArea();
    cardManager = new WCardManager();
    card1 = new WText();
    card2 = new WText();
    root.add(containerChild);
    root.add(simpleChild);
    root.add(repeaterChild);
    root.add(cardManager);
    containerChild.add(grandChild);
    cardManager.add(card1);
    cardManager.add(card2);
    root.setLocked(true);
    setActiveContext(new UIContextImpl());
    repeaterChild.setData(Arrays.asList(new String[] { "1", "2", "3" }));
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WContainer(com.github.bordertech.wcomponents.WContainer) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WCardManager(com.github.bordertech.wcomponents.WCardManager) WTextField(com.github.bordertech.wcomponents.WTextField) WRepeater(com.github.bordertech.wcomponents.WRepeater) Before(org.junit.Before)

Example 5 with WApplication

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

the class ServerCache method wrapUI.

/**
 * @param ui the UI component
 * @return the UI component wrapped in WApplication
 */
private static WApplication wrapUI(final WComponent ui) {
    WApplication egUI;
    if (ui instanceof WApplication) {
        egUI = (WApplication) ui;
    } else {
        egUI = new WApplication();
        egUI.add(ui);
    }
    return egUI;
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication)

Aggregations

WApplication (com.github.bordertech.wcomponents.WApplication)28 Test (org.junit.Test)14 UIContext (com.github.bordertech.wcomponents.UIContext)13 WComponent (com.github.bordertech.wcomponents.WComponent)8 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)4 WLabel (com.github.bordertech.wcomponents.WLabel)4 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)3 WText (com.github.bordertech.wcomponents.WText)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 PrintWriter (java.io.PrintWriter)3 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 WWindow (com.github.bordertech.wcomponents.WWindow)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 Map (java.util.Map)2 Before (org.junit.Before)2 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)1 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)1 Environment (com.github.bordertech.wcomponents.Environment)1