3 Replies Latest reply on Oct 5, 2006 3:10 AM by bmhardy

    NullpointerException in MyFacesGenericPortlet after Redeploy

    Martin Schmidt Newbie

      Hi everyone!

      I have a facelet implemented with the org.apache.myfaces.portlet.MyFacesGenericPortlet and a xhtml referencing a session bean.

      after modifying the xhtml and redeploying my ear (containing the portlet) I get a NullPointerException and I have to restart the whole application server.
      Since restarting the application server after each modification causes a really high test-debug-code interval time, I need urgently a solution for this problem.

      The NullPointerException comes in the method org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender:
      
      java.lang.NullPointerException
       at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:393)
       at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:266)
       at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:167)
       at javax.portlet.GenericPortlet.render(GenericPortlet.java:407)
       at org.jboss.portal.portlet.PortletContainer.invokeRender(PortletContainer.java:512)
      



      Could anybody tell me what I have to care for when I use the MyFacesGenericPortlet?


      Thanks in advance,

      Martin

        • 1. Workaround: NullpointerException in MyFacesGenericPortlet af
          Martin Schmidt Newbie

          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 Newbie

            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 Newbie

              Adding another note to be notified of posts