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>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); } }Modifier and Type | Field and Description |
---|---|
static String |
KEY |
_scopes, s_standardScopes
Constructor and Description |
---|
GuiceResolver() |
Modifier and Type | Method and Description |
---|---|
Object |
getValue(javax.el.ELContext ctx,
Object base,
Object property) |
getCommonPropertyType, getFeatureDescriptors, getType, isReadOnly, runtimeConfig, setValue
public static final String KEY
public Object getValue(javax.el.ELContext ctx, Object base, Object property) throws NullPointerException, javax.el.PropertyNotFoundException, javax.el.ELException
getValue
in class ManagedBeanResolver
NullPointerException
javax.el.PropertyNotFoundException
javax.el.ELException
Copyright © 2016 The Apache Software Foundation. All Rights Reserved.