通过< ui:include>有条件地包含Facelet文件 [英] Conditionally including a Facelet file via <ui:include>

查看:119
本文介绍了通过< ui:include>有条件地包含Facelet文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个Facelets文件(index.xhtml和report.xhtml).我使用RichFaces <ui:include src="report.xhtml"/>将报表加载到索引中.工作正常. 但是,当我尝试仅在特定条件下显示报告时,我将失败!这是行不通的:

I have 2 Facelets files (index.xhtml and report.xhtml). I use the RichFaces <ui:include src="report.xhtml"/> to load the report into the index. Works fine. But when I try to only show report on certain conditions, I fail! What does not work is this:

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

ui:include的呈现属性似乎不起作用.

The rendered attribute of ui:include does not seem to work.

在某些情况下如何将report.xhtml加载到index.xhtml中?我的代码中的错误在哪里?

How can I load the report.xhtml into the index.xhtml on certain conditions? Where is the error in my code?

其中一半现在可以使用.更改Facelet文件符合条件.但是,已加载的Facelet的功能无法正常工作.这是为什么?代码中的问题在哪里?

Half of it works now. Changing the Facelet file works with conditions. But the functionality of the loaded Facelet does not work properly. Why is that? Where is the problem in the code?

基于我现在的建议:

<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>

这是我的报告Facelet.如果我在没有任何条件的情况下使用报表Facelet的功能,则可以正常工作,但是如果我使用在 Edit 1 中发布的条件加载该报表,则<rich:panelMenuItem .../>的按钮将不再起作用,并且<h:outputText escape="false" value="#{reportService.content}"/>不会加载内容.知道为什么吗?

This is my report Facelet. If I use without any condition the functionality of the report Facelet works perfectly, but if I load it using the condition I posted in Edit 1, then the buttons of <rich:panelMenuItem .../> don't work anymore and <h:outputText escape="false" value="#{reportService.content}"/> does not load the content. Any idea why?

修改3:

更改了<rich:panel header="Report">...</rich:panel>,但行为仍保持不变.

Changed the <rich:panel header="Report">...</rich:panel>, but behaviour still unchanged.

<!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>

推荐答案

尝试使用ui:fragment围绕ui:include标签,如下所示:-

try to surround your ui:include tag with ui:fragment as follows :-

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

这篇关于通过&lt; ui:include&gt;有条件地包含Facelet文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆