Hi.
I frequently - but far from always get a NPE when I use the variable resolver to resolve a session scope variable. Does anyone have any idea of what I am doing wrong?
The setup is this.
I have set up a session scope backing bean let's call it my myBean.
I have a servlet that generates graphic elements for some pages based on the information in myBean.
In the servlet I do the following:
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
FacesContextFactory fcf =
(FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory =
(LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
facesContext = fcf.getFacesContext(getServletContext(),
req,
resp,
lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE
));
}
if (facesContext != null) {
VariableResolver vr = facesContext.getApplication().getVariableResolver();
if (vr != null) {
Object o = vr.resolveVariable(facesContext, "myBean");
}
}
As I started to say the line:
vr.resolveVariable(facesContext, "myBean");
somtimes throw a NPE with the following trace:
java.lang.NullPointerException
at
org.apache.myfaces.context.servlet.SessionMap.setAttribute(SessionMap.java:50)
at
org.apache.myfaces.context.servlet.AbstractAttributeMap.put(AbstractAttributeMap.java:104)
at
org.apache.myfaces.el.VariableResolverImpl$13.put(VariableResolverImpl.java:192)
at
org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:328)
at
org.apache.myfaces.config.LastVariableResolverInChain.resolveVariable(LastVariableResolverInChain.java:42)
Any ideas?
Thanks
Mads

