org.apache.myfaces.el.unified.resolver
Class GuiceResolver

java.lang.Object
  extended by javax.el.ELResolver
      extended by org.apache.myfaces.el.unified.resolver.ManagedBeanResolver
          extended by org.apache.myfaces.el.unified.resolver.GuiceResolver

public class GuiceResolver
extends ManagedBeanResolver

Register this ELResolver in faces-config.xml.

<application> <el-resolver>org.apache.myfaces.el.unified.resolver.GuiceResolver</el-resolver> </application>

Implement and configure a ServletContextListener in web.xml .

<listener> com.your_company.GuiceServletContextListener</listener-class> </listener>

Configure Guice in your ServletContextListener implementation, and place the Injector in application scope.

public class GuiceServletContextListener implements ServletContextListener { public void contextInitialized(ServletContextEvent event) { ServletContext ctx = event.getServletContext(); //when on Java6, use ServiceLoader.load(com.google.inject.Module.class); Injector injector = Guice.createInjector(new YourModule()); ctx.setAttribute(GuiceResolver.KEY, injector); } public void contextDestroyed(ServletContextEvent event) { ServletContext ctx = event.getServletContext(); ctx.removeAttribute(GuiceResolver.KEY); } }

Author:
Dennis Byrne

Field Summary
static String KEY
           
 
Fields inherited from class org.apache.myfaces.el.unified.resolver.ManagedBeanResolver
_scopes, STANDARD_SCOPES
 
Fields inherited from class javax.el.ELResolver
RESOLVABLE_AT_DESIGN_TIME, TYPE
 
Constructor Summary
GuiceResolver()
           
 
Method Summary
 Object getValue(javax.el.ELContext ctx, Object base, Object property)
           
 
Methods inherited from class org.apache.myfaces.el.unified.resolver.ManagedBeanResolver
getCommonPropertyType, getFeatureDescriptors, getType, isReadOnly, runtimeConfig, setValue
 
Methods inherited from class javax.el.ELResolver
invoke
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY

public static final String KEY
Constructor Detail

GuiceResolver

public GuiceResolver()
Method Detail

getValue

public Object getValue(javax.el.ELContext ctx,
                       Object base,
                       Object property)
                throws NullPointerException,
                       javax.el.PropertyNotFoundException,
                       javax.el.ELException
Overrides:
getValue in class ManagedBeanResolver
Throws:
NullPointerException
javax.el.PropertyNotFoundException
javax.el.ELException


Copyright © 2014 The Apache Software Foundation. All Rights Reserved.