Soc*_*tes 0 jsf richfaces facelets jsf-2
我有2个Facelets文件(index.xhtml和report.xhtml).我使用RichFaces <ui:include src="report.xhtml"/>将报告加载到索引中.工作良好.但是,当我尝试仅显示某些条件的报告时,我失败了!什么不起作用是这样的:
<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>
Run Code Online (Sandbox Code Playgroud)
编辑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>
Run Code Online (Sandbox Code Playgroud)
尝试用ui:fragment包围你的ui:include标签,如下所示: -
<ui:fragment rendered="#{indexService.contentName eq 'report'}">
<ui:include src="report.xhtml" />
</ui:fragment>
Run Code Online (Sandbox Code Playgroud)