首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSF/Primefaces: ui:insert in ui:include

JSF/Primefaces: ui:insert in ui:include
EN

Stack Overflow用户
提问于 2014-10-07 15:29:11
回答 2查看 13.6K关注 0票数 3

我希望使用ui:insert/ui:define来替换模板文件中的某些内容。在模板文件中有另一个文件的包含,在这个文件中是ui:insert

ui:define在这种情况下不起作用。但是,如果footer.xhtml文件的代码包含在template.xhtml中,ui:define运行良好。

难道不可能在ui:include中使用ui:insert/ui:define吗?

template.xhtml:

代码语言:javascript
复制
<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>

--

代码语言:javascript
复制
<util:footer /> 

也可以写成ui:include,结果与.

footer.xhtml:

代码语言:javascript
复制
<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:(片段)

代码语言:javascript
复制
<ui:composition template="template.xhtml">
  <ui:define name="replace">         
    <h:panelGroup>
       <div>
          <p:outputLabel value="test"/>
       </div>
    </h:panelGroup>
  </ui:define>
</ui:composition>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-09 07:22:34

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

代码语言:javascript
复制
<ui:decorate template="footer.xhtml" />

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

更多信息在这里:What is the real conceptual difference between ui:decorate and ui:include?

票数 2
EN

Stack Overflow用户

发布于 2014-10-08 07:22:11

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26239687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档