2 Replies Latest reply on Sep 30, 2011 8:05 AM by 891712

    How to carry across a Facet through nested composite components

    tjahnsen
      Hello

      I have two nested composite components, with an inner component that does interesting things, and an outer that groups some child components in a convenient package. I would like to use a Facet in the inner component, and it would be nice if you could declare it on the outer component and have it passed through. But I am unable to achieve this, and there is no documentation on how it should work.

      I've made a test project where I try to use insertFacet in the outer component.

      Main page 'index.xhtml':
      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:test="http://java.sun.com/jsf/composite/facettest">
          <h:head>
              <title>NestedFacetTest</title>
          </h:head>
          <h:body>
              <div>PageTopElement</div>
              <test:outerCC>
                  <f:facet name="testFacet">
                      <div>FacetElement</div>
                  </f:facet>
              </test:outerCC>
              <div>PageBottomElement</div>
              <br/>
      
              <div>PageTopElement2</div>
              <test:innerCC>
                  <f:facet name="testFacet">
                      <div>FacetElement2</div>
                  </f:facet>
              </test:innerCC>
              <div>PageBottomElement2</div>
          </h:body>
      </html>
      The outer composite component 'outerCC.xhtml' where I would like the Facet to be carried across:
      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:composite="http://java.sun.com/jsf/composite"
            xmlns:test="http://java.sun.com/jsf/composite/facettest">
      
          <!-- INTERFACE -->
          <composite:interface>
              <composite:facet name="testFacet"/>
          </composite:interface>
      
          <!-- IMPLEMENTATION -->
          <composite:implementation>
              <div>OuterTopElement</div>
              <test:innerCC>
                  <composite:insertFacet name="testFacet"/>
              </test:innerCC>
              <div>OuterBottomElement</div>
          </composite:implementation>
      </html>
      The inner composite component 'innerCC.xhtml' where I would like to use the Facet:
      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:composite="http://java.sun.com/jsf/composite">
      
          <!-- INTERFACE -->
          <composite:interface>
              <composite:facet name="testFacet"/>
          </composite:interface>
      
          <!-- IMPLEMENTATION -->
          <composite:implementation>
              <div>InnerTopElement</div>
              <composite:renderFacet name="testFacet"/>
              <div>InnerBottomElement</div>
          </composite:implementation>
      </html>
      When I run the main page, I get the Facet text when I use innerCC directly, but not when I use outerCC. What do I do wrong, and how can I change the code so that the Facet is carried through to a nested composite component?

      I run GlassFish 3 with Mojarra 2.0.2 (FCS b10).

      Kind regards,
      Thomas Jahnsen