本文介绍了即使呈现为false,也始终包含JSF 2.0-< ui:include> xhtml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个主页xhtml,其中根据条件包括3个子xhtml.我面临的问题是,无论发生什么情况,Book.xhtml总是被调用.我将呈现的条件更改为false或移至另一个条件,但是该文件始终被调用,由于该文件的后备bean也被调用,导致不必要的开销.请为我提供解决方案

I have a home page xhtml where i am including 3 child xhtml based on conditions.The issue i am facing is , whatever be the scenario,Book.xhtml always gets invoked.I changed the rendered condition to false or move out to another condition, but the file always gets invoked Due to which its backing bean also is invoked causing unwanted overhead.Please provide me a solution

<ui:composition template="/xhtml/baseLayout.xhtml">
    <ui:define name="browserTitle">
        <h:outputText value="HOME PAGE" />
    </ui:define>
    <ui:define name="header">
        <ui:include src="/xhtml/header.xhtml" />
    </ui:define>
    <ui:define name="bodyContent">

        <h:panelGrid width="100%"
            rendered="#{pogcore:isRoleAuthorized(BUNDLE.SUPER)}"  >
            <ui:include src="/xhtml/SuperUser.xhtml"  />
        </h:panelGrid>
        <h:panelGrid width="100%"
            rendered="#{pogcore:isRoleAuthorized(BUNDLE.MAINTENANCE)}" >
            <ui:include src="/xhtml/Maintenance.xhtml" />
        </h:panelGrid>

        <h:panelGrid width="100%"
            rendered="#{pogcore:isRoleAuthorized(BUNDLE.PRINT)}">
            <ui:include src="/xhtml/Book.xhtml" />
        </h:panelGrid>

    </ui:define>
</ui:composition>

推荐答案

这是由于jsf的生命周期而发生的.在视图渲染期间评估JSF UIComponent,而在构建时评估jstl标签.

This is happening due to lifecycle of jsf. JSF UIComponents are evaluated during view render time where as jstl tags are evaluated at build time.

因此,当您使用h:panelGrid的rendered属性时,为时已晚,不能在包含的页面下调用托管bean.要解决此问题,请尝试使用jstl标签,以下方法应适用于您.

So when you use rendered attribute of h:panelGrid it is too late to not invoke managed beans under the included page. To resolve this try having conditions using jstl tag, the following should work for you.

<c:if test="#{bean.yourCondition}">
    <h:panelGrid width="100%">
        <h:outputText value="#{bean.yourCondition}"/> <!--if this is not getting printed there is smtg wrong with your condition, ensure the syntax, the method signature is correct-->
        <ui:include src="/xhtml/Book.xhtml" />
    </h:panelGrid>
</c:if>
<c:if test="#{!bean.yourCondition}">
    <h:outputText value="#{bean.yourCondition}"/> <!--This should print false-->
</c:if>

下面的文档描述了jstl和jsf生命周期的详细信息.

The document below describes the details of jstl and jsf lifecycle.

请查看以下文档,以查看不使用jstl标记即可解决此问题的另一种方法.

Check the following document to see another way to solve this without using jstl tags.

这篇关于即使呈现为false,也始终包含JSF 2.0-&lt; ui:include&gt; xhtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:33