3

I want to use ui:insert/ui:define to replace some content in a template file. Inside the template file there is an include of another file and inside this file is the ui:insert

The ui:define is not working in this case. If however the code of the footer.xhtml file is included in the template.xhtml the ui:define is working fine.

Is it not possible to use ui:insert/ui:define inside an ui:include?

template.xhtml:

<html 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"
      xmlns:sec="http://www.springframework.org/security/facelets/tags"
      xmlns:debug="http://XYZ/jsf/debug"
      xmlns:util="http://XYZ/ibk/util"
      xmlns:p="http://primefaces.org/ui">

    <h:body >

        <f:view>
            <div id="headerWrapper">
                <!-- META-NAVIGATION -->
                <div id="metanavWrapper"  >
                    <div class="ui-helper-clearfix pagewidth" >
                        <ui:include src="metanav.xhtml" />
                    </div>
                </div>

            </div>

            <div id="contentWrapper" >
                <!--div id="content" class="pagewidth"-->
                <div id="content">
                    <div id="contentMenuLeft">
                        <ui:include src="navigationMenu.xhtml" />
                    </div>
                    <div id="contentDisplay">
                        <ui:insert name="content" />
                        <ui:insert name="help" />

                    </div>
                </div>
            </div>

            <util:footer />

        </f:view>

        <ui:insert name="dialog"/>

    </h:body>
</html>

--

<util:footer /> 

could also be written as ui:include, results in the same...

footer.xhtml:

<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"
                xmlns:sec="http://www.springframework.org/security/facelets/tags"
                xmlns:p="http://primefaces.org/ui"
                >

   <div id="footerWrapper">
      <f:subview id="footerWrapper">


         <h:panelGroup id="footer" >
            <div >

               <ui:insert name="replace" />

            </div>
         </h:panelGroup>
      </f:subview>


   </div>



</ui:composition>

another.xhtml: (snippet)

<ui:composition template="template.xhtml">
  <ui:define name="replace">         
    <h:panelGroup>
       <div>
          <p:outputLabel value="test"/>
       </div>
    </h:panelGroup>
  </ui:define>
</ui:composition>
OPaczkowski
  • 51
  • 1
  • 1
  • 4

2 Answers2

2

The solution is to include the footer.xhtml in the template.xhtml by

<ui:decorate template="footer.xhtml" />

Then the insert/define is working!

More info here: What is the real conceptual difference between ui:decorate and ui:include?

Community
  • 1
  • 1
OPaczkowski
  • 51
  • 1
  • 1
  • 4
0

If i get it right, your <ui:define name="replace">will never work without the footer, because the corresponding <ui:insert name="replace" /> is inside of it and only exists when the footer is included. No insert, no define.

When you call your another.xhtml (or any other site with template="..." ), the compiler will assemble all includes first and then add all all defineed code at the places of the corresponding insert-tags.

Dawn
  • 126
  • 6
  • I that would be true, the code above should work, because footer.xhtml is included in template.xhtml So either the process is the other way around (isert/define before include), or there is an error in the code... – OPaczkowski Oct 08 '14 at 07:57
  • have you tried the real ``- include? – Dawn Oct 08 '14 at 09:48
  • Yes, tried that. Is not working, either. Is that working for you? Then I would probably have an error in my code. – OPaczkowski Oct 08 '14 at 10:53
  • It is working in my project. I have a project-specific template.xhtml that has an underlayed base-template. Inside template.xhtml, the parameter application is defined. The ui:insert for "application" is nested in a extra xhtml that is included in the base-template. Perhaps try : – Dawn Oct 08 '14 at 12:47
  • Wrapping the insert in an include doesn't help. Can you/someone probably post your/their working code? – OPaczkowski Oct 08 '14 at 15:22