Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3942

<f:viewParam binding> causes NPE because UIViewRoot is null

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.6
    • Fix Version/s: 2.2.7
    • Component/s: None
    • Labels:
      None
    • Environment:
      Tomcat 8.0.14 and TomEE 2.0.0 snapshot.

      Description

      Using binding attribute on <f:viewParam> as follows:

      <f:viewParam name="foo" binding="#{foo}" />
      

      causes regardless of the binding location (Facelet itself as demonstrated above, request scoped bean, session scoped bean, etc) the following exception:

      java.lang.NullPointerException
      	at org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.createComponent(ComponentTagHandlerDelegate.java:534)
      	at org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.apply(ComponentTagHandlerDelegate.java:284)
      	at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:50)
      	at org.apache.myfaces.view.facelets.tag.jsf.core.ViewMetadataHandler.apply(ViewMetadataHandler.java:85)
      	at org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:195)
      	at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
      	at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
      	at org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:188)
      	at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage$FaceletViewMetadata.createMetadataView(FaceletViewDeclarationLanguage.java:2752)
      	at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:255)
      	at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196)
      	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143)
      	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
      	... 
      

      Turns out that UIViewRoot is null while the code didn't expect that.

        Activity

        Hide
        lu4242 Leonardo Uribe added a comment -

        This is caused by a chicken-egg problem at the time the metadata is created. f:viewParam is created before FacesContext.setViewRoot(...) is called. But the problem is we cannot call it when the metadata is created because this is something defined by the spec. By that reason ComponentSupport.getViewRoot(...) fails.

        The solution is add a fail-safe approach to get the view root when facelets algorithm is executed.

        Show
        lu4242 Leonardo Uribe added a comment - This is caused by a chicken-egg problem at the time the metadata is created. f:viewParam is created before FacesContext.setViewRoot(...) is called. But the problem is we cannot call it when the metadata is created because this is something defined by the spec. By that reason ComponentSupport.getViewRoot(...) fails. The solution is add a fail-safe approach to get the view root when facelets algorithm is executed.
        Hide
        lu4242 Leonardo Uribe added a comment -

        Thanks to Bauke Scholtz for the report.

        Show
        lu4242 Leonardo Uribe added a comment - Thanks to Bauke Scholtz for the report.

          People

          • Assignee:
            lu4242 Leonardo Uribe
            Reporter:
            balusc Bauke Scholtz
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development