PrimeFaces rendered attribute impact on performance

蹲街弑〆低调 提交于 2020-01-17 12:43:06

问题



I'm developing a JSF application with PrimeFaces in which i plan to use mainly tabViews (multiple ones). To give you a general idea about how the application is going to work, I have a side menu from which the user should be able to choose "modules" that will display in the center layout as Tabs. Seeing as I have multiple "modules" and there will be more in the future, the solution I've decided on using is writing the code for all the tabs I have in the xhtml and then using the rendered attribute (set to false by default) in order to display them (when the user clicks on the corresponding menu).

Now comes my question, is setting a component's rendered attribute to false equivalent to that component not being there at all (no impact at performance at all)?


回答1:


Now comes my question, is setting a component's rendered attribute to false equivalent to that component not being there at all (no impact at performance at all)?

It's NOT equivalent. If you set rendered=false, the component is still there in the component tree on the server side. Therefor it costs a little bit performance and memory.

Mojarra also had big performance problems in the past when the component tree is bigger: https://blog.oio.de/2013/05/16/jsf-performance-mojarra-improves-dramatically-with-latest-release/




回答2:


To use your xhtml page like a template, follow this steps

Step 1 : Create my included page

<ui:composition  xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:p="http://primefaces.org/ui"
                 xmlns:f="http://java.sun.com/jsf/core"
                 >

<h:form id="form">
  ... 
</h:form>
</ui:composition>

Let say that the name of this page is myTemplate.xhtml

Step 2 : use your template page each time you need it

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/templates/templateCrb.xhtml"
                xmlns:p="http://primefaces.org/ui"
                > 

    <ui:define name="MyContent">
        <ui:include src="/pages/.../myTemplate.xhtml">
        </ui:include>
    </ui:define>
</ui:composition>    

In this case i included a complete page, but you can use it in a dialog, a tabView, you can also send parameter to you include element.

You can read more in more informations about include.

Hope that helped you.



来源:https://stackoverflow.com/questions/42926106/primefaces-rendered-attribute-impact-on-performance

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