JSF/Primefaces: ui:insert in ui:include



我想使用ui:interse/ui:define来替换模板文件中的一些内容。在模板文件中有另一个文件的include,在这个文件中是ui:insert

在这种情况下,ui:define不起作用。但是,如果footer.xhtml文件的代码包含在template.xhtml中,则ui:define可以正常工作。

是否不可能在ui:include中使用ui:insert/ui:define?

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 /> 

也可以写成ui:include,结果相同。。。

页脚.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:(片段)

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

解决方案是通过将footer.xhtml包含在template.xhtml中

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

那么插入/定义就开始工作了!

更多信息请点击这里:ui:decorate和ui:include在概念上的真正区别是什么?

如果我做对了,你的<ui:define name="replace">永远不会在没有页脚的情况下工作,因为对应的<ui:insert name="replace" />就在其中,只有在包含页脚时才存在。没有插入,就没有定义。

当您调用another.xhtml(或任何其他具有template="..."的站点)时,编译器将首先组装所有include,然后在相应的insert-标记的位置添加所有defineed代码。

最新更新