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

NullPointerException in BodyRenderer if there is no head in the facelet

    Details

      Description

      In com.liferay.faces.bridge.renderkit.html_basic.internal.BodyRendererBridgeImpl, there is a possible bug when head component is missing from the portlet the body renderer throws NullPointerException because attribute HEAD_RESOURCES_TO_RENDER_IN_BODY is never set and is null.

       

      Usage for no head portlet view is when you want portlet included in theme via theme.runtime and you include its resources in themes head, thus you do not want those resources to be loaded in portlet itself. (I haven't found better way to do it)

       

      In portal-impl-3.0.0 (link) it looks like it can be fixed with just a simple nullcheck around the for each loop between lines 115-127.

      There is possible workaround with SystemEventListener just set it to default empty list. Check code below.

      public class NoHeadFixerPhaseListener implements SystemEventListener {
      
         private static final String HEAD_RESOURCES_TO_RENDER_IN_BODY = "headResourcesToRenderInBody";
      
         @Override
         public void processEvent(SystemEvent event) throws AbortProcessingException {
            Map<Object, Object> facesContextAttribtues =  FacesContext.getCurrentInstance().getAttributes();
            if (facesContextAttribtues.get(HEAD_RESOURCES_TO_RENDER_IN_BODY) == null) {
               facesContextAttribtues.put(HEAD_RESOURCES_TO_RENDER_IN_BODY,      Collections.emptyList());
            }
         }
      
         @Override
         public boolean isListenerForSource(Object source) {
            return true; //depends on your use, for our use there was only one registred portlet so I just left it to true since it is called for one UIViewRoot
         }
      }
      
      and in faces-config.xml add
      <application>
         <system-event-listener>
         <system-event-listener-class&gt;cz.vrk.pi.ou.NoHeadFixerPhaseListener</system-event-listener-class&gt;
         <system-event-class&gt;javax.faces.event.PostAddToViewEvent</system-event-class&gt;
         <source-class&gt;javax.faces.component.UIViewRoot</source-class&gt;
         </system-event-listener>
      </application>

        Attachments

          Activity

            People

            Assignee:
            neil.griffin Neil Griffin
            Reporter:
            nitram94@gmail.com Martin Vaněk
            Participants of an Issue:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Packages

                Version Package
                bridge-impl-3.1.0
                bridge-impl-4.1.0