-
1. Workaround: NullpointerException in MyFacesGenericPortlet af
martplus Feb 22, 2006 5:15 AM (in response to martplus)Workaround:
I subclassed MyFacesGenericPortlet and overrided two methods. The problem was, that the sessionTimeout(...) detector method did not work properly, because there is always as session in this context. I added the SESSION_LIVE_FLAG attribute to the session....package com.msshop.admin.portal; import javax.portlet.PortletException; import javax.portlet.PortletRequest; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.myfaces.context.servlet.ServletFacesContextImpl; import org.apache.myfaces.portlet.MyFacesGenericPortlet; public class GenericAdminPortlet extends MyFacesGenericPortlet { private static final String SESSION_LIVE_ATTR = "msshop.SESSION_LIVE_ATTR"; private static final Log log = LogFactory.getLog(MyFacesGenericPortlet.class); public GenericAdminPortlet() { super(); } /** * Render a JSF view. */ protected void facesRender(RenderRequest request, RenderResponse response) throws PortletException, java.io.IOException { if (log.isTraceEnabled()) log.trace("called facesRender"); setContentType(request, response); String viewId = request.getParameter(VIEW_ID); boolean nonFacesRequest = (viewId == null) || sessionTimedOut(request); request.getPortletSession(true).setAttribute(SESSION_LIVE_ATTR, Boolean.TRUE); if (nonFacesRequest) { setPortletRequestFlag(request); nonFacesRequest(request, response); return; } setPortletRequestFlag(request); try { ServletFacesContextImpl facesContext = (ServletFacesContextImpl) request.getPortletSession().getAttribute(CURRENT_FACES_CONTEXT); if (facesContext == null) { facesContext = (ServletFacesContextImpl) facesContext(request, response); request.getPortletSession().setAttribute(CURRENT_FACES_CONTEXT, facesContext); } // TODO: not sure if this can happen. Also double check this against // spec section 2.1.3 if (facesContext.getResponseComplete()) return; facesContext.setExternalContext(makeExternalContext(request, response)); lifecycle.render(facesContext); } catch (Throwable e) { handleExceptionFromLifecycle(e); } } protected boolean sessionTimedOut(PortletRequest request) { if (super.sessionTimedOut(request)) return true; Object flag = request.getPortletSession(false).getAttribute(SESSION_LIVE_ATTR); return flag == null; } }
-
2. Re: NullpointerException in MyFacesGenericPortlet after Rede
bmhardy Oct 5, 2006 3:01 AM (in response to martplus)Thanks for the great post. We kept getting the null pointer exception and would have to restart the portal for things to work. Very annoying when working on development.
I took your code and created a new YYYGenericPortlet and then used that in our config file rather than MyFacesGenericPortlet. The null pointer problem went away, but now we get a message that says:
viewToRender must not be null
We cannot get out of this state unless we once again restart the portal server.
Can you offer any insight.
Any help is much appreciated.
Thanks -
3. Re: NullpointerException in MyFacesGenericPortlet after Rede
bmhardy Oct 5, 2006 3:10 AM (in response to martplus)Adding another note to be notified of posts