Example usage for org.apache.wicket Application getRequestCycleListeners

List of usage examples for org.apache.wicket Application getRequestCycleListeners

Introduction

In this page you can find the example usage for org.apache.wicket Application getRequestCycleListeners.

Prototype

public RequestCycleListenerCollection getRequestCycleListeners() 

Source Link

Usage

From source file:com.github.javawithmarcus.wicket.cdi.CdiConfiguration.java

License:Apache License

protected synchronized void configure(String appKey, Application application, ConfigurationParameters params) {

    if (parameters.containsKey(appKey)) {
        params = parameters.get(appKey);
        if (params.isConfigured()) {
            throw new IllegalStateException("Cannot configure CdiConfiguration multiple times");
        }// ww w .  j a  va2 s  .  co  m
    } else {
        parameters.put(appKey, params);
    }
    params.getIgnoredPackages().addAll(Arrays.asList(defaultIgnoredPackages));

    RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
    application.getRequestCycleListeners().add(listeners);

    // enable conversation propagation
    if (params.getPropagation() != ConversationPropagation.NONE) {
        enablePropagation(params, application);
    }

    // enable detach event
    listeners.add(detachEventEmitter);

    // inject application instance
    if (params.isInjectApplication()) {
        nonContextualManager.postConstruct(application);
    }

    // enable injection of various framework components

    if (params.isInjectSession()) {
        application.getSessionListeners().add(sessionInjector);
    }

    if (params.isInjectComponents()) {
        application.getComponentInstantiationListeners().add(componentInjector);
    }

    if (params.isInjectBehaviors()) {
        application.getBehaviorInstantiationListeners().add(behaviorInjector);
    }

    // enable cleanup

    application.getApplicationListeners().add(new CdiShutdownCleaner(params.isInjectApplication()));

    params.setConfigured(true);
}

From source file:com.github.javawithmarcus.wicket.cdi.CdiConfiguration.java

License:Apache License

private void enablePropagation(ConfigurationParameters params, Application application) {
    disablePropagation(params); // Force remove active listeners if any
    IRequestCycleListener requestCycleListener = conversationPropagator;// new RequestCycleListenerWrapper();
    application.getRequestCycleListeners().add(requestCycleListener);
    params.setActiveRequestCycleListener(requestCycleListener);

    IComponentOnBeforeRenderListener componentOnBeforeRenderListener = new ComponentOnBeforeRenderListenerWrapper();
    application.getComponentPreOnBeforeRenderListeners().add(componentOnBeforeRenderListener);
    params.setActiveComponentOnBeforeRenderListener(componentOnBeforeRenderListener);
}

From source file:com.vanillasource.jaywire.wicket.WicketModule.java

License:Open Source License

private void registerInfrastructure(Application application) {
    application.getRequestCycleListeners().add(new AbstractRequestCycleListener() {
        @Override/*  w  w  w.ja v a  2 s  . c  o  m*/
        public void onBeginRequest(RequestCycle requestCycle) {
            if (requestCycle.getRequest() != null && requestCycle.getRequest() instanceof ServletWebRequest) {
                ServletRequest request = ((ServletWebRequest) requestCycle.getRequest()).getContainerRequest();
                getServletRequestScope().setStorage(request);
                // Force creation of session
                if (request instanceof HttpServletRequest) {
                    application.getSessionStore().getSessionId(requestCycle.getRequest(), true);
                    Session session = application.fetchCreateAndSetSession(requestCycle);
                    if (session == null) {
                        throw new WicketRuntimeException(
                                "Could not create session, which is necessary for JayWire session scope.");
                    }
                    getHttpSessionScope().setStorage(((HttpServletRequest) request).getSession());
                }
            }
        }

        @Override
        public void onEndRequest(RequestCycle requestCycle) {
            getHttpSessionScope().clearStorage();
            getServletRequestScope().clearStorage();
        }
    });
    application.getApplicationListeners().add(new IApplicationListener() {
        @Override
        public void onAfterInitialized(Application application) {
        }

        @Override
        public void onBeforeDestroyed(Application application) {
            try {
                close();
            } catch (Exception e) {
                throw new WicketRuntimeException("Could not close JayWire module", e);
            }
        }
    });
}

From source file:de.alpharogroup.wicket.base.util.application.ApplicationExtensions.java

License:Apache License

/**
 * Sets the deployment exception settings for the given application.
 *
 * @param application/*from ww  w .java2 s.  c  o m*/
 *            the application
 * @param applicationRequestCycleListener
 *            the application request cycle listener
 */
public static void setExceptionSettingsForDeployment(final Application application,
        final AbstractRequestCycleListener applicationRequestCycleListener) {
    // show the exception page from us...
    application.getExceptionSettings()
            .setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
    // In case of unhandled exception redirect it to a custom page
    application.getRequestCycleListeners().add(applicationRequestCycleListener);
}

From source file:org.jaulp.wicket.base.util.application.ApplicationUtils.java

License:Apache License

/**
 * Sets the deployment exception settings for the given application.
 *
 * @param application/*from www .j  a  v a2 s.  com*/
 *            the application
 * @param applicationRequestCycleListener
 *            the application request cycle listener
 */
public static void setExceptionSettingsForDeployment(final Application application,
        final AbstractRequestCycleListener applicationRequestCycleListener) {
    // show the exception page from us...
    application.getExceptionSettings()
            .setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
    // In case of unhandled exception redirect it to a custom page
    application.getRequestCycleListeners().add(applicationRequestCycleListener);
}

From source file:org.opensingular.internal.form.wicket.util.WicketSerializationDebugUtil.java

License:Apache License

/**
 * Adiciona listener na aplicao para fazer o teste se ao final de cada renderizao de pgina, a pgina 
 * serializvel. Passa a gera uma informao de tamanho e tempo da serializao no log da aplicao. Gera um log de
 * exception se a pgina no for serializvel.
 *
 * @param application    A ser adicionada a verificao
 * @param targetClassLog Classe para o qual ser gerado os logs da verificao
 *///w  w  w  .  j a v a  2  s  .c o m
public static void configurePageSerializationDebug(Application application, Class<?> targetClassLog) {
    //Configura os listeners para verificao da serializao
    DebugSerializationListener debugger = new DebugSerializationListener(targetClassLog);
    application.getComponentOnAfterRenderListeners().add(debugger);
    application.getRequestCycleListeners().add(new DebugSerializationRequestCycleListeners(debugger));
    //Ativa a pilha de serializao detalhada
    if (!"true".equals(System.getProperty("sun.io.serialization.extendedDebugInfo"))) {
        System.setProperty("sun.io.serialization.extendedDebugInfo", "true");
    }
}

From source file:org.wicketstuff.jamon.application.JamonInitializer.java

License:Apache License

@Override
public void init(Application application) {
    application.setMetaData(MonitoringRepositoryKey.KEY, new JamonRepository());
    application.getRequestCycleListeners().add(new JamonAwareRequestCycleListener(application, true));
}