webtier@glassfish.java.net

ui:composition with template behaving strangely

From: <webtier_at_javadesktop.org>
Date: Wed, 28 Apr 2010 10:22:20 PDT

I am seeing some strange behavior when trying to convert a JSF 1.2 app in GF2 to JSF 2 in GF3. It worked fine previously. Here is the problem.

I have a simple page as follows:

    <ui:composition template="/WEB-INF/layout/layout.xhtml">
      <ui:define name="header"/>
      <ui:define name="content">
          This is contents. Test1 starts.
          <a:test1
              testAttribute="attribute1"/>
          <a:test2
              testAttribute="attribute2"/>
          Test1 ends.
      </ui:define>
      <ui:define name="footer">
      </ui:define>
    </ui:composition>

Here is test1.xhtml

    <ui:composition template="/WEB-INF/facelets/tags/section.xhtml">
        <ui:define name="section-content">
            This is test1
            #{testAttribute}
        </ui:define>
    </ui:composition>

And here is test2.xhtml

    <ui:composition template="/WEB-INF/facelets/tags/section.xhtml">
        <ui:define name="section-content">
            This is test2
            #{testAttribute}
        </ui:define>
    </ui:composition>


The output you would expect would be as follows

This is contents. Test1 starts.
This is test1 attribute1
This is test2 attribute2
Test1 ends


The output we are actually getting is as follows:

This is contents. Test1 starts.
This is test1 attribute1
This is test1 attribute2
Test1 ends


Notice that the static content in test2.xhtml is using the content from test1.xhtml, but the new attribute value is used.

If we remove the template from the composition, and instead use the ui:decorate tag, then things display as expected.

Did the expected behavior of ui:composition change in JSF 2, or is it broken?

Thanks,
Joel
[Message sent by forum member 'jweight']

http://forums.java.net/jive/thread.jspa?messageID=399435