Jsf 2.0-<ui:include>xhtml included always even if rendered is false

烂漫一生 提交于 2019-11-30 10:33:55

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.

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>

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

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

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

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

Do this:

  • Always include the sub pages
  • Put the panelGrid (with the rendered) inside the page that you always include

Why ? Because the inclusion is performed before the rendered is evaluated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!