gpt4 book ai didi

jsf 2.0-xhtml included always even if rendered is false

转载 作者:行者123 更新时间:2023-12-04 22:27:06 24 4
gpt4 key购买 nike

我有一个主页 xhtml,其中根据条件包含 3 个子 xhtml。
我面临的问题是,无论情况如何,Book.xhtml 总是被调用。
我将渲染条件更改为 false 或移出到另一个条件,但文件总是被调用由于它的支持 bean 也被调用,从而导致不必要的开销。
请给我一个解决方案

<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 UIComponents 在 View 渲染时被评估,而 jSTL 标签在构建时被评估。

因此,当您使用 h:panelGrid 的渲染属性时,不调用包含页面下的托管 bean 为时已晚。要解决此问题,请尝试使用 jSTL 标签设置条件,以下内容应该适合您。

<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 生命周期的细节。

http://www.znetdevelopment.com/blogs/2008/10/18/jstl-with-jsffacelets/



查看以下文档以查看另一种不使用 jSTL 标签来解决此问题的方法。

http://pilhuhn.blogspot.com/2009/12/facelets-uiinclude-considered-powerful.html

关于jsf 2.0-<ui :include>xhtml included always even if rendered is false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14394290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com