Uploaded image for project: 'PUBLIC - Liferay Faces'
  1. PUBLIC - Liferay Faces
  2. FACES-3237

NullPointerException when accessing the LiferayPortletHelper from a resource request

    Details

      Description

      This is a followup to -FACES-1212-. I ran into similar problems in AJAX requests.

      The problem is here (I stripped the code comments):

      com.liferay.faces.portal.context.internal.LiferayPortletHelperImpl.java
      public Portlet getPortlet() {
      	PortletRequest portletRequest = getPortletRequest();
      	Portlet portlet = (Portlet) portletRequest.getAttribute(WebKeys.RENDER_PORTLET);
      
      	if (portlet == null) {
      		Liferay liferayManagedBean = getLiferayManagedBean();
      		portlet = liferayManagedBean.getPortlet();
      	}
      	return portlet;
      }
      

      In my case the liferayManagedBean is null. I guess because I'm using JEE with CDI - but I didn't look into that further.

      What I'm wondering: Even if it is not null, what happens if the liferayManagedBean wasn't initialized a in render request before? As it uses the same WebKeys.RENDER_PORTLET attribute, it won't have access to the portlet either. And why don't you use the portlet attached to the portlet request?

      I'm using now is this code:

      com.liferay.faces.portal.context.internal.LiferayPortletHelperImpl.java
      public Portlet getPortlet() {
      	PortletRequest portletRequest = getPortletRequest();
      	while (portletRequest instanceof PortletRequestWrapper) {
      		portletRequest = ((PortletRequestWrapper) request).getRequest();
      	}
      	if (portletRequest instanceof LiferayPortletRequest) {
      		return ((LiferayPortletRequest) portletRequest ).getPortlet();
      	}
      
      	// Legacy code 
      	Portlet portlet = (Portlet) portletRequest.getAttribute(WebKeys.RENDER_PORTLET);
      
      	if (portlet == null) {
      		Liferay liferayManagedBean = getLiferayManagedBean();
      		portlet = liferayManagedBean.getPortlet();
      	}
      
      	return portlet;
      }

      The same I did for an extension of the liferay bean that I put into the JEE scope.

      This returns always a portlet for me, even in a resource request. And I think the cast to 
      LiferayPortletRequest is using the same internal knowledge as the access to WebKeys.RENDER_PORTLET - I mean both access methods are equally "dangerous" when looking at interoperability.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: