MyFaces Core
  1. MyFaces Core
  2. MYFACES-3329

Fix PSS algorithm to ensure c:if and ui:include src="#{...}" related use cases will work without rely on org.apache.myfaces.REFRESH_TRANSIENT_BUILD_ON_PSS_PRESERVE_STATE

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.10, 2.1.4
    • Component/s: JSR-314
    • Labels:
      None

      Description

      There is a well known issue related to use c:if and ui:include src="#

      {...}". It has been described in different ways for a long time. For example see:

      MYFACES-3271 ui:include tag handler evaluates its bindings to soon during JSF lifecycle

      There is a lot of related issues but to keep things simple, PSS algorithm is based on the following conditions:

      1. Each time the view is build by first time or when it is restored, the same initial state will be retrieved.
      2. It is possible to calculate a delta state, based on that initial state.

      In practice, there are some use cases that breaks that:

      a. c:if tag
      b. c:choose, c:when and c:otherwise
      c. ui:include src="#{...}

      " (usually known as "dynamic include")
      d. ui:decorate template="#

      {...}

      "
      e. c:forEach

      The reason is they change the component tree dynamically. For example a c:if tag could be bound to a ValueExpression that in one moment could be true and then false, so the "initial state" calculated by PSS algorithm through a vdl.buildView() will be different each time, breaking condition 1.

      It is true there exists the workaround with org.apache.myfaces.REFRESH_TRANSIENT_BUILD_ON_PSS_PRESERVE_STATE, which mark some parts of the tree to be restored fully, so it does not matter the initial state, at the end just we restore such parts fully and everything works as facelets 1.1.x. But even so, it is a workaround, and we need a better solution to that.

      In practice, points a., b., c. and d. are relevant. The case e. related to c:forEach is not because the iterated data has

      usually a life longer than the view (session, conversation or view scope), so we can exclude this case.

      The solution to this problem is store the result of the evaluated expressions within the view. It is the only that will work

      as good as org.apache.myfaces.REFRESH_TRANSIENT_BUILD_ON_PSS_PRESERVE_STATE.

      To do that we need to generate an unique id per tag and make components and tags inside them generate unique tags too but the

      same ids should be generated each time the view is build no matter the conditions. For example:

      <h:outputText value="A"/>
      <c:if test="#

      {condition}

      ">
      <h:outputText value="B"/>
      </c:if>
      <h:outputText value="C"/>

      C should have the same id each time, no matter what happen inside c:if. Since PSS algorithm uses clientIds to store the "delta" state of the components, ensure that is CRITICAL, otherwise the state will get mixed or lost.

      Additionally, we must restore that "facelet state" before the view is built to use it when the initial state is derived.

      1. MYFACES-3329-2.0.x-1.patch
        127 kB
        Leonardo Uribe
      2. MYFACES-3329-2.1.x-1.patch
        126 kB
        Leonardo Uribe
      3. MYFACES-3329-2.1.x-2.patch
        127 kB
        Leonardo Uribe

        Issue Links

        There are no Sub-Tasks for this issue.

          Activity

          No work has yet been logged on this issue.

            People

            • Assignee:
              Leonardo Uribe
              Reporter:
              Leonardo Uribe
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development