Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.tectonica.guice;
An optional injector for Mojarra-based applications where dependency injection is required into the @ManagedBeans. It extends com.sun.faces.vendor.WebContainerInjectionProvider, which normally handles invocations of @PostConstruct and @PreDestroy, by also adding dependency-injection for @ManagedBeans using the Guice injector created in GuiceListener. This creator, by the way, also handles @PostConstruct methods, so we make sure to avoid double invocation here.

To use, add the following paragraph to web.xml alongside your other JSF configuration:

NOTE: make sure your GuiceListener-subclass is an active listener in the web.xml, or NullPointerExceptions will be thrown

Zach Melamed
	public void inject(Object managedBeanthrows InjectionProviderException
		if (isToBeInjectedByGuice(managedBean))

as an arbitrary choice, the choice here is to inject only into @ManagedBean instances, so that other classes - not written by us - wouldn't be injected too. This choice could be altered.

	private boolean isToBeInjectedByGuice(Object managedBean)
		return managedBean.getClass().getAnnotation(ManagedBean.class) != null;
	public void invokePostConstruct(Object managedBeanthrows InjectionProviderException
		// @PostConstruct is already handled in classes we injected
		if (!isToBeInjectedByGuice(managedBean))
	public void invokePreDestroy(Object managedBeanthrows InjectionProviderException
New to GrepCode? Check out our FAQ X