【问题标题】:JSF/Primefaces: ui:insert in ui:includeJSF/Primefaces: ui:insert in ui:include
【发布时间】:2014-12-02 02:20:12
【问题描述】:

我想使用 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>

另一个.xhtml: (sn-p)

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

【问题讨论】:

    标签: jsf jsf-2 primefaces insert include


    【解决方案1】:

    解决方法是在template.xhtml中包含footer.xhtml by

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

    那么插入/定义就起作用了!

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 那是真的,上面的代码应该可以工作,因为footer.xhtml包含在template.xhtml中所以要么这个过程是相反的(在include之前isert/define),要么有代码中的错误...
      • 你试过真正的&lt;ui:include src="footer.xhtml" /&gt;-include吗?
      • 是的,试过了。也不行。这对你有用吗?那么我的代码可能会出错。
      • 它在我的项目中工作。我有一个特定于项目的 template.xhtml,它有一个底层的基本模板。在 template.xhtml 中,定义了参数应用程序。 “应用程序”的 ui:insert 嵌套在基本模板中包含的额外 xhtml 中。也许试试:
      • 将插入包含在包含中没有帮助。您/某人可以发布您/他们的工作代码吗?
      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多