2014-10-16 27 views
0

我有2個Facelets文件(index.xhtml和report.xhtml)。我使用RichFaces <ui:include src="report.xhtml"/>將報告加載到索引中。工作正常。 但是,當我試圖只顯示某些條件的報告,我失敗了!不起作用的是:有條件地包含一個Facelet文件通過<ui:include>

<ui:include src="report.xhtml" rendered="#{indexService.contentName == 'report'}"/>

ui:include的呈現屬性似乎不起作用。

如何在特定條件下將report.xhtml加載到index.xhtml中?我的代碼中的錯誤在哪裏?

編輯:

的一半,現在的作品。更改Facelet文件適用於條件。但是加載的Facelet的功能無法正常工作。這是爲什麼?代碼中的問題在哪裏?

基礎上的建議,我現在有這樣的:

<h:form> 
    <h:panelGrid> 
     <a4j:commandLink value="Home" render="contentpanel" action="#{indexService.setContentName('home')}"/> 
     <a4j:commandLink value="Report" render="contentpanel" action="#{indexService.setContentName('report')}"/> 
    </h:panelGrid> 
</h:form> 
<a4j:outputPanel id="contentpanel"> 
    <ui:fragment rendered="#{indexService.contentName eq 'report'}"> 
     <ui:include src="report.xhtml" /> 
    </ui:fragment> 
</a4j:outputPanel> 

編輯2:

這是我的報告的facelet。如果我在沒有任何條件的情況下使用,報告Facelet的功能完美地工作,但是如果使用我發佈在編輯1中的條件加載它,則<rich:panelMenuItem .../>的按鈕不再工作,<h:outputText escape="false" value="#{reportService.content}"/>不會加載內容。任何想法爲什麼?

編輯3:

改變了<rich:panel header="Report">...</rich:panel>,但仍表現持平。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j"> 
    <ui:composition> 
     <h:outputStylesheet> 
      .placesmenu { 
       width: 200px; 
       vertical-align: top; 
      } 

      .contentplace { 
       vertical-align: top; 
      } 
     </h:outputStylesheet> 
     <h:panelGrid columns="2" width="100%" columnClasses="placesmenu, contentplace"> 
      <rich:panel header="Places"> 
       <h:form> 
        <rich:panelMenu style="width: 170px"> 
         <a4j:repeat value="#{reportService.menuItems}" var="menuItem" id="repeat_layer1"> 
          <rich:panelMenuGroup label="#{menuItem.label}"> 
           <a4j:repeat value="#{menuItem.subMenuItemList}" var="subMenuItem" id="repeat_layer2"> 
            <rich:panelMenuItem label="#{subMenuItem.label}" render="reportpanel" onbeforedomupdate="#{reportService.setId(subMenuItem.id)}"/> 
           </a4j:repeat> 
          </rich:panelMenuGroup> 
         </a4j:repeat> 
        </rich:panelMenu> 
       </h:form> 
      </rich:panel> 
      <rich:panel header="Report"> 
       <h:outputText escape="false" value="#{reportService.content}" id="reportpanel"/> 
      </rich:panel> 
     </h:panelGrid> 
    </ui:composition> 
</html> 
+0

我使用的編程NetBeans和它提示我說。 – Socrates 2014-10-16 14:15:25

回答

5

嘗試圍繞你的用戶界面:包括與UI標籤:片段如下: -

<ui:fragment rendered="#{indexService.contentName eq 'report'}"> 
    <ui:include src="report.xhtml" /> 
</ui:fragment> 
+0

非常感謝您的快速回答。它現在工作一半。我在我的主要帖子中發佈了我的當前狀態。請看看。 – Socrates 2014-10-16 14:13:46

+0

你能解釋你的生意做什麼以及你期望從包含的頁面做什麼! – Scorpion 2014-10-16 14:22:11

+0

好的。呃,其實很簡單。我有Facelets for Reports,照片,備忘錄......在Index Facelet中,我將它們放在一起。因此,對於每個我有一個鏈接我想點擊然後加載適當的一個。就是這樣。如上所述,非常容易。你爲什麼這樣問?我的方法完全錯誤嗎? – Socrates 2014-10-16 14:33:40

相關問題