Search in sources :

Example 1 with Request

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

the class AbstractContainerHelper method processAction.

/**
 * Support standard processing of the action phase of a request.
 *
 * @throws IOException if there is an IO error on writing a response.
 */
public void processAction() throws IOException {
    if (isDisposed()) {
        LOG.error("Skipping action phase. Attempt to reuse disposed ContainerHelper instance");
        return;
    }
    try {
        // Check user context has been prepared
        if (getNewConversation() == null) {
            throw new IllegalStateException("User context has not been prepared before the action phase");
        }
        prepareAction();
        UIContext uic = getUIContext();
        if (uic == null) {
            throw new IllegalStateException("No user context set for the action phase.");
        }
        UIContextHolder.pushContext(uic);
        // Make sure maps are cleared up
        uic.clearScratchMap();
        uic.clearRequestScratchMap();
        prepareRequest();
        Request req = getRequest();
        getInterceptor().attachResponse(getResponse());
        getInterceptor().serviceRequest(req);
        if (req.isLogout()) {
            handleLogout();
            dispose();
        }
    } catch (ActionEscape esc) {
        LOG.debug("ActionEscape performed.");
        // Action escapes must be handled in the action phase and then
        // do nothing if they reach the render phase (which they will in
        // the servlet implementation)
        handleEscape(esc);
        dispose();
    } catch (Escape esc) {
        LOG.debug("Escape performed during action phase.");
    // We can't handle the escape until the render phase.
    } catch (Throwable t) {
        // We try not to let any exception propagate to container.
        String message = "Caught exception during action phase.";
        LOG.error(message, t);
        // We can't handle the error until the render phase.
        propogateError(t);
    } finally {
        UIContextHolder.reset();
    }
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) UIContext(com.github.bordertech.wcomponents.UIContext) Request(com.github.bordertech.wcomponents.Request)

Example 2 with Request

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

the class WContentExample method addContentRow.

/**
 * Adds components to the given container which demonstrate various ways of acessing the given content.
 *
 * @param contentDesc the description of the content, used to label the controls.
 * @param contentAccess the content which will be displayed.
 * @param target the container to add the UI controls to.
 */
private void addContentRow(final String contentDesc, final ContentAccess contentAccess, final MutableContainer target) {
    // Demonstrate WButton + WContent, round trip
    WButton button = new WButton(contentDesc);
    final WContent buttonContent = new WContent();
    button.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            buttonContent.setContentAccess(contentAccess);
            buttonContent.display();
        }
    });
    WContainer buttonCell = new WContainer();
    buttonCell.add(buttonContent);
    buttonCell.add(button);
    target.add(buttonCell);
    // Demonstrate WButton + WContent, using AJAX
    WButton ajaxButton = new WButton(contentDesc);
    final WContent ajaxContent = new WContent();
    ajaxButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            ajaxContent.setContentAccess(contentAccess);
            ajaxContent.display();
        }
    });
    WContainer ajaxCell = new WContainer();
    // The WContent must be wrapped in an AJAX targetable container
    WPanel ajaxContentPanel = new WPanel();
    ajaxContentPanel.add(ajaxContent);
    ajaxCell.add(ajaxButton);
    ajaxCell.add(ajaxContentPanel);
    ajaxButton.setAjaxTarget(ajaxContentPanel);
    target.add(ajaxCell);
    // Demonstrate WContentLink - new window
    WContentLink contentLinkNewWindow = new WContentLink(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            setContentAccess(contentAccess);
        }
    };
    target.add(contentLinkNewWindow);
    // Demonstrate WContentLink - prompt to save
    WContentLink contentLinkPromptToSave = new WContentLink(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            setContentAccess(contentAccess);
        }
    };
    contentLinkPromptToSave.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
    target.add(contentLinkPromptToSave);
    // Demonstrate WContentLink - inline
    WContentLink contentLinkInline = new WContentLink(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            setContentAccess(contentAccess);
        }
    };
    contentLinkInline.setDisplayMode(DisplayMode.DISPLAY_INLINE);
    target.add(contentLinkInline);
    // Demonstrate targeting of content via a URL
    WMenu menu = new WMenu(WMenu.MenuType.FLYOUT);
    final WContent menuContent = new WContent();
    menuContent.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
    WMenuItem menuItem = new WMenuItem(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            menuContent.setContentAccess(contentAccess);
            setUrl(menuContent.getUrl());
        }
    };
    menu.add(menuItem);
    WContainer menuCell = new WContainer();
    menuCell.add(menuContent);
    menuCell.add(menu);
    target.add(menuCell);
}
Also used : Action(com.github.bordertech.wcomponents.Action) WContainer(com.github.bordertech.wcomponents.WContainer) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WContent(com.github.bordertech.wcomponents.WContent) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) Request(com.github.bordertech.wcomponents.Request) WMenu(com.github.bordertech.wcomponents.WMenu) WButton(com.github.bordertech.wcomponents.WButton) WContentLink(com.github.bordertech.wcomponents.WContentLink)

Example 3 with Request

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

the class InterceptorComponent_Test method testAttachUIBadBacking.

@Test(expected = IllegalStateException.class)
public void testAttachUIBadBacking() {
    InterceptorComponent interceptor = new InterceptorComponent(new WebComponent() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void serviceRequest(final Request request) {
        // NO-OP
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void preparePaint(final Request request) {
        // NO-OP
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void paint(final RenderContext renderContext) {
        // NO-OP
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String getName() {
            return null;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String getId() {
            return null;
        }
    });
    // This should throw an exception, as it doesn't know how to attach the UI
    // to the anonymous WebComponent implementation.
    interceptor.attachUI(new WLabel());
}
Also used : WebComponent(com.github.bordertech.wcomponents.WebComponent) RenderContext(com.github.bordertech.wcomponents.RenderContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Aggregations

Request (com.github.bordertech.wcomponents.Request)3 Action (com.github.bordertech.wcomponents.Action)1 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 Escape (com.github.bordertech.wcomponents.Escape)1 RenderContext (com.github.bordertech.wcomponents.RenderContext)1 UIContext (com.github.bordertech.wcomponents.UIContext)1 WButton (com.github.bordertech.wcomponents.WButton)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WContent (com.github.bordertech.wcomponents.WContent)1 WContentLink (com.github.bordertech.wcomponents.WContentLink)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMenu (com.github.bordertech.wcomponents.WMenu)1 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 WebComponent (com.github.bordertech.wcomponents.WebComponent)1 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1 Test (org.junit.Test)1