我希望使用ui:insert/ui:define来替换模板文件中的某些内容。在模板文件中有另一个文件的包含,在这个文件中是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,结果与.
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:(片段)
<ui:composition template="template.xhtml">
<ui:define name="replace">
<h:panelGroup>
<div>
<p:outputLabel value="test"/>
</div>
</h:panelGroup>
</ui:define>
</ui:composition>发布于 2014-10-09 07:22:34
解决方案是将footer.xhtml包含在template.xhtml中
<ui:decorate template="footer.xhtml" />那么插入/定义就开始工作了!
更多信息在这里:What is the real conceptual difference between ui:decorate and ui:include?
发布于 2014-10-08 07:22:11
如果我做对了,您的<ui:define name="replace">将永远不会在没有页脚的情况下工作,因为对应的<ui:insert name="replace" />在其中,并且只在包含页脚时才存在。没有插入,没有定义。
当您调用another.xhtml (或使用template="..."的任何其他站点)时,编译器将首先组装所有include,然后在相应的insert-tags位置添加所有defineed代码。
https://stackoverflow.com/questions/26239687
复制相似问题