我想有条件地输出一些Facelets代码.
为此,JSTL标签似乎工作正常:
<c:if test="${lpc.verbose}">
...
</c:if>
Run Code Online (Sandbox Code Playgroud)
但是,我不确定这是否是最佳做法?还有另一种方法来实现我的目标吗?
我有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: …Run Code Online (Sandbox Code Playgroud)