Guice Variable Resolver


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public class GuiceVariableResolver extends VariableResolver {
  2. private final VariableResolver wrapped;
  3.  
  4. public GuiceVariableResolver(VariableResolver wrapped) {
  5. if (wrapped == null)
  6. throw new NullPointerException("wrapped " + VariableResolver.class.getName());
  7. this.wrapped = wrapped;
  8. }
  9.  
  10. @SuppressWarnings("unchecked")
  11. @Override
  12. public Object resolveVariable(FacesContext fctx, String name) throws EvaluationException {
  13. Object resolved = wrapped.resolveVariable(fctx, name);
  14. if (resolved != null) {
  15. Map<String, Object> map = fctx.getExternalContext().getApplicationMap();
  16. Injector injector = (Injector) map.get(Injector.class.getName());
  17. if (injector == null)
  18. throw new NullPointerException("Could not locate " + "Guice Injector in application scope using"
  19. + " key '" + Injector.class.getName() + "'");
  20. injector.injectMembers(resolved);
  21. }
  22. return resolved;
  23. }
  24.  
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.