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

f:metadata section removed when refresh view and is not included in the template directly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.0.17, 2.1.11
    • JSR-314
    • None

    Description

      Suppose this example:

      ex1.xhtml

      <ui:composition template="/META-INF/templates/template1.xhtml">
      <f:metadata>
      <f:viewParam name="id"/>
      </f:metadata>
      <ui:define name="container">
      <h1>Myfaces Examples</h1>
      <h:messages/>
      <h:form id="mainForm">
      <h:commandButton value="POSTBACK"/>
      </h:form>
      </ui:define>
      </ui:composition>

      The template page (template1.xhtml) includes the content under "container" section but note f:metadata is outside that part so it is not included.

      The compilation suppose 2 steps:

      • Build a view metadata facelet, which only has what's inside <f:metadata> section, no matter where is it.
      • Build a normal facelet, which builds the component tree itself.

      In this case, when the normal facelet is applied, the section under f:metadata is removed by facelets refresh algorithm, because it is not included in that facelet. It is an effect that is difficult to see, but it appear when you have a preRenderView listener or in the tests using JSF 2.2 f:viewAction.

      The spec javadoc suggest do this instead:

      <ui:composition template="/META-INF/templates/template1.xhtml">
      <ui:define name="metadata">
      <f:metadata>
      <f:viewParam name="id"/>
      </f:metadata>
      <!-- ..... -->
      </ui:define>

      And add in the template on the top level a simple <ui:insert name="metadata/> to include the section when facelets process the page.

      Other alternative is use this syntax:

      <ui:composition
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
      <f:metadata>
      <f:viewParam name="id"/>
      </f:metadata>
      <ui:decorate template="template1.xhtml">

      It also works but the point is f:metadata is never inside a <c:if> section or any other that changes the tree structure dynamically, because the compilation suppose only it should be located at the top page level and not in a template client.

      So, the first syntax should be valid, and its more, even put f:metadata outside ui:composition should work, because the syntax is smaller.

      The proposed fix is exclude f:metadata facet from mark/delete algorithm, just adding some lines in DefaultFacelet.

      Attachments

        Activity

          People

            lu4242 Leonardo Uribe
            lu4242 Leonardo Uribe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: