Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF/Primefaces: ui:insert in ui:include

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>
like image 978
OPaczkowski Avatar asked Jan 26 '26 18:01

OPaczkowski


1 Answers

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?

like image 156
OPaczkowski Avatar answered Jan 28 '26 10:01

OPaczkowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!