Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-100

<f:view> erases conversation id UIViewRoot attribute in JSF 2

XMLWordPrintable

    • Hide

      Don't use <f:view>. In that case, JSF continues to work with the same UIViewRoot it created in the Restore View phase.

      Show
      Don't use <f:view>. In that case, JSF continues to work with the same UIViewRoot it created in the Restore View phase.

      JSF 2 now builds the view in the Render Response phase. If JSF encounters the <f:view> tag while building the view, it resets the UIViewRoot, wiping out any attributes that might have been set in a phase listener before the Render Response phase. Thus, the conversation id becomes a vicitim of this sweep:

      FacesContext.getCurrentInstance().getViewRoot().getAttributes().put(CONVERSATION_PROPAGATION_KEY, cid);

      This problem is not present in JSF 1 since the view is already constructed by the time this call is made by the WebBeansPhaseListener before the Render Response phase.

      The solution is to approach conversation propagation differently for JSF 2. Instead of using a phase listener, a SystemEventListener should be used that monitors the PreRenderViewEvent. SystemEventListeners can be registered programmatically, which should be done sometime after JSF 2 starts (the version of JSF can be detected in WebBeans)

              dan.j.allen Dan Allen (Inactive)
              dan.j.allen Dan Allen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: