List of usage examples for org.apache.wicket Application getApplicationListeners
public final ApplicationListenerCollection getApplicationListeners()
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"); }/*from w w w . ja va 2s . c o 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.vanillasource.jaywire.wicket.WicketModule.java
License:Open Source License
private void registerInfrastructure(Application application) { application.getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override/* w w w. j av a 2 s. com*/ 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); } } }); }