Return to Snippet

Revision: 22720
at January 20, 2010 08:02 by kungfoo


Initial Code
public class GuiceVariableResolver extends VariableResolver {
	private final VariableResolver wrapped;

	public GuiceVariableResolver(VariableResolver wrapped) {
		if (wrapped == null)
			throw new NullPointerException("wrapped " + VariableResolver.class.getName());
		this.wrapped = wrapped;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object resolveVariable(FacesContext fctx, String name) throws EvaluationException {
		Object resolved = wrapped.resolveVariable(fctx, name);
		if (resolved != null) {
			Map<String, Object> map = fctx.getExternalContext().getApplicationMap();
			Injector injector = (Injector) map.get(Injector.class.getName());
			if (injector == null)
				throw new NullPointerException("Could not locate " + "Guice Injector in application scope using"
						+ " key '" + Injector.class.getName() + "'");
			injector.injectMembers(resolved);
		}
		return resolved;
	}

}

Initial URL

                                

Initial Description

                                

Initial Title
Guice Variable Resolver

Initial Tags

                                

Initial Language
Java