2014-10-16 60 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