Example usage for org.apache.wicket IApplicationListener IApplicationListener

List of usage examples for org.apache.wicket IApplicationListener IApplicationListener

Introduction

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

Prototype

IApplicationListener

Source Link

Usage

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

License:Open Source License

private void registerInfrastructure(Application application) {
    application.getRequestCycleListeners().add(new AbstractRequestCycleListener() {
        @Override/*from   w w  w.j a  v  a  2s. co  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.components.examples.application.WicketApplication.java

License:Apache License

@Override
protected void onDevelopmentModeSettings() {
    super.onDevelopmentModeSettings();
    // Demonstration how to install the debug plugin...
    new ApplicationDebugSettingsPlugin() {
        /**/*from  w  w w. j av  a2  s. c  o  m*/
         * The serialVersionUID
         */
        private static final long serialVersionUID = 1L;

        /**
         * {@inheritDoc}
         */
        @Override
        protected void onConfigure(final WebApplication application) {
            super.onConfigure(application);
            // Adds the references from source code to the browser to reference in eclipse....
            WicketSource.configure(application);
        };
    }.install(this);

    // add an applicationListener...
    this.getApplicationListeners().add(new IApplicationListener() {
        /**
         * {@inheritDoc}
         */
        @Override
        public void onAfterInitialized(final Application application) {
            LOGGER.info("Wicket application is initialized");
            // here can comes code that is needed after the application
            // initialization...
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onBeforeDestroyed(final Application application) {
            LOGGER.info("Wicket application is destroyed");
            // here can comes code that is needed before the application
            // been destroyed...
        }
    });
    // strip wicket tags...
    this.getMarkupSettings().setStripWicketTags(true);
}

From source file:sf.wicklet.gwt.site.server.db.H2Configurator.java

License:Apache License

public static void addApplicationListener(final EmbeddedDatabase db, final String path) {
    Application.get().getApplicationListeners().add(new IApplicationListener() {
        @Override//from  w  w w  . j  a v a  2s .co m
        public void onBeforeDestroyed(final Application application) {
            if (Config.DEBUG) {
                System.out.println("# Shutting down database: " + path);
            }
            db.shutdown();
        }

        @Override
        public void onAfterInitialized(final Application application) {
        }
    });
}