Uploaded image for project: 'RichFaces'
  1. RichFaces
  2. RF-13452

UIDataAdaptor must not register as listener for PostAddToViewEvent in its constructor

    Details

    • Steps to Reproduce:
      Hide

      Use Mojarra 2.1.26.
      Dynamically add a UIDataTable or UITree to a JSF view.
      Let JSF render the response.
      Submit a new AJAX request from the resulting page.
      Now, in RESTORE_VIEW, the NPE is thrown.

      Show
      Use Mojarra 2.1.26. Dynamically add a UIDataTable or UITree to a JSF view. Let JSF render the response. Submit a new AJAX request from the resulting page. Now, in RESTORE_VIEW, the NPE is thrown.
    • Workaround:
      Workaround Exists
    • Workaround Description:
      Hide

      When you create a UIDataAdaptor dynamically, replace the UIDataAdaptor by your own ComponentSystemEventListener. Unsubscribe UIDataAdator from itself: dataAdaptor.unsubscribeFromEvent(PostAddToViewEvent.class, dataAdaptor).

      Create your own ComponentSystemEventListener and register it:
      dataAdaptor.subscribeToEvent(PostAddToViewEvent.class, new MyListener())

      In your MyListener's implementation of processEvent(ComponentSystemEvent): unsubscribe the UIDataAdaptor,too, but delegate to it:

      event.getComponent().unsubscribeFromEven((PostRestoreStateEvent.class, event.getComponent());
      event.getComponent().processEvent(event);

      Show
      When you create a UIDataAdaptor dynamically, replace the UIDataAdaptor by your own ComponentSystemEventListener. Unsubscribe UIDataAdator from itself: dataAdaptor.unsubscribeFromEvent(PostAddToViewEvent.class, dataAdaptor) . Create your own ComponentSystemEventListener and register it: dataAdaptor.subscribeToEvent(PostAddToViewEvent.class, new MyListener()) In your MyListener 's implementation of processEvent(ComponentSystemEvent) : unsubscribe the UIDataAdaptor,too, but delegate to it: event.getComponent().unsubscribeFromEven((PostRestoreStateEvent.class, event.getComponent()); event.getComponent().processEvent(event);

      Description

      Whenever a component which is based on org.richfaces.component.UIDataAdaptor is added dynamically, NPE occurs in the next RESTORE_VIEW Phase when using Mojarra 2.1.x.

      My first guess was, that this would be an error in Mojarra (issue 2152, see https://java.net/jira/browse/JAVASERVERFACES-2152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ),
      which occurs whenever a sub-class of UIComponent registers itself as javax.faces.event.SystemEventListener for
      javax.faces.event.PostAddToViewEvent in ist constructor, just like UIDataAdaptor does.

      Now, Manfred Riem of Mojarra argues (in the very issue named above), that registering for PostAddToView in the constructor is a design flaw in itself.

      Note that the error occurs with every UIComponent which is added dynamically and which registers itself as PostAddToView listener in its constructor. For the Mojarra issue, I provided a simple component which extends the standard JSF HtmlOutputText and registers itself in its constructor, too. Baam - same error. So maybe more components of RichFaces are affected - not just those based on UIDataAdaptor.

      For completion, here is a stack trace:

      Schwerwiegend: java.lang.NullPointerException
      at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2526)
      at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
      at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2163)
      at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2111)
      at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:289)
      at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
      at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2203)
      at javax.faces.component.UIComponentBase.doPostAddProcessing(UIComponentBase.java:1885)
      at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:405)
      at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2637)
      at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2609)
      at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreDynamicAdd(FaceletPartialStateManagementStrategy.java:421)
      at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreDynamicActions(FaceletPartialStateManagementStrategy.java:247)
      at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:570)
      at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:138)
      at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:653)
      at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142)
      at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:301)
      at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:301)
      at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                lutzulrich Lutz Ulrich
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: