Search in sources :

Example 1 with RedirectPolicy

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler.RedirectPolicy in project wicket by apache.

the class ListenerRequestHandler method respond.

@Override
public void respond(final IRequestCycle requestCycle) {
    final IRequestablePage page = getPage();
    final boolean freshPage = pageComponentProvider.doesProvideNewPage();
    final boolean isAjax = ((WebRequest) requestCycle.getRequest()).isAjax();
    IRequestableComponent component;
    try {
        component = getComponent();
    } catch (ComponentNotFoundException e) {
        // either the page is stateless and the component we are looking for is not added in the
        // constructor
        // or the page is stateful+stale and a new instances was created by pageprovider
        // we denote this by setting component to null
        component = null;
    }
    if ((component == null && !freshPage) || (component != null && component.getPage() != page)) {
        throw new ComponentNotFoundException("Component '" + getComponentPath() + "' has been removed from page.");
    }
    if (page instanceof Page) {
        // initialize the page to be able to check whether it is stateless
        ((Page) page).internalInitialize();
    }
    RedirectPolicy policy = page.isPageStateless() ? RedirectPolicy.NEVER_REDIRECT : RedirectPolicy.AUTO_REDIRECT;
    boolean blockIfExpired = component != null && !component.canCallListenerAfterExpiry();
    boolean lateComponent = component == null && freshPage;
    if ((pageComponentProvider.wasExpired() && blockIfExpired) || lateComponent) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("An IRequestListener was called but its page/component({}) couldn't be resolved. " + "Scheduling re-create of the page and ignoring the listener interface...", getComponentPath());
        }
        if (isAjax) {
            policy = RedirectPolicy.ALWAYS_REDIRECT;
        }
        requestCycle.scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(new PageProvider(page), policy));
        return;
    }
    invokeListener(requestCycle, policy, isAjax);
}
Also used : RedirectPolicy(org.apache.wicket.core.request.handler.RenderPageRequestHandler.RedirectPolicy) IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) WebRequest(org.apache.wicket.request.http.WebRequest) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Page(org.apache.wicket.Page) IRequestablePage(org.apache.wicket.request.component.IRequestablePage)

Aggregations

Page (org.apache.wicket.Page)1 RedirectPolicy (org.apache.wicket.core.request.handler.RenderPageRequestHandler.RedirectPolicy)1 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 WebRequest (org.apache.wicket.request.http.WebRequest)1