0


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

RedaN
  • 93
  • 1
  • 10
  • yes , but the it does impact your performance, the thing that impact your performance is your request to the CPU and the complexity of the query – Yagami Light Mar 21 '17 at 11:58
  • for example it's better to use memory to store a result of a complexe operation that repeat the operation each time you need it – Yagami Light Mar 21 '17 at 12:01
  • @YagamiLight does that mean that i can have as many components as i want with no impact on performance as long as their rendered attribute is set to false ? – RedaN Mar 21 '17 at 12:02
  • yes and non : please give an estimation about how many possible xhtml files you have to create – Yagami Light Mar 21 '17 at 12:04
  • don't forget that each page you create it's a space that you use in your application each time you deploy your app it will take some time but for the user if the pages isn't complexe it does impact the user experience – Yagami Light Mar 21 '17 at 12:06
  • @YagamiLight the things is i want to use two xhtml max, one for login and the other for the rest of the application – RedaN Mar 21 '17 at 12:07
  • you can use include please read this post : [use include](http://stackoverflow.com/questions/4792862/how-to-include-another-xhtml-in-xhtml-using-jsf-2-0-facelets) (you create two xhtml pages and use it in all your application) – Yagami Light Mar 21 '17 at 12:09
  • does it correspond to what you want to do ?!? – Yagami Light Mar 21 '17 at 12:23
  • @YagamiLight sorry for the late answer. Yes thank you, I think the include approach could work, all i need now is to figure out if i can use the included pages as tabs – RedaN Mar 21 '17 at 14:30
  • no problem, and yes you can use it in tabView, i right an answer about it ?!? – Yagami Light Mar 21 '17 at 14:34
  • @YagamiLight yes please – RedaN Mar 21 '17 at 14:37

2 Answers2

1

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.

Community
  • 1
  • 1
Yagami Light
  • 1,756
  • 4
  • 19
  • 39
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/

tandraschko
  • 2,291
  • 13
  • 13
  • Thanks for the clarification, for now i'm using the method suggested by Yagami Light above with my own twist on it that i think won't impact the performance : i have all the tabs in the main page and i control their rendered attributes along with the source attribute for the include tags inside them from my managed bean(in other ways the source of the include tags is empty until its parent tab rendered attribute becomes true) – RedaN Mar 23 '17 at 15:32