• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

component creation in JSF

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Quick question regarding component creation in JSF.

In the following example, if my items has 10 objects then 10 outputText component will be created and another 10 outputText component will be created but it will be rendered based on some condition?

<h:dataTable var="item" value="#{bean.items}>
<h:outputText value="#{item.text}"/>
<h:outputText value="#{item.desc}" rendered="#{item.rendered}"/>
</h:dataTable>

My question is if I have 1000 items then 1000 * 2 outputText components will be created in memory. How do we avoid creating too many components in the memory? Is it possible? How ui:repeat tag will be helpful in this situation?

Please advice.

Thanks,
Saravanan
 
Saloon Keeper
Posts: 23899
162
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, there'd be 1000 model row elements consisting of 2000 text items and 1000 boolean items. The rendering would be controlled by a property returned by the isRendered in the model row class. Technically, any or all of the properties (text and boolean) might not be distinct depending on how you implement the model row, but I'm going for the brute-force case.

The datatable model is not the database model, so having 1000 items in it isn't really a good idea, since that means you'll be returning 1000 rows to the user's web browser on a single page request. That means time, bandwidth, and a strong possibility of overloading the user's eyeballs. I rarely top 50 rows/page myself.

Just to elaborate, the datatable model is not the database model, but it can be a window into the database model. This is possible, since elements in a Java collection are not copied by value, but simply references. Thus a data item in a database model collection can be referred to by other collections (such as the datatable model), but only one copy of the actual data would exist.
 
Kumar Saravanan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for your reply. I never get 1000 items in collection and show them to the user at any point of time. Thanks for your valuable advice. Just for example, I mentioned it in my above post.

BuildTimeVsRenderTime

I was going through the above link and find the following code and its explanation ->



Explanation:-

In this case both the input and the output components are created.

The rendered is evaluated by the renderer during the rendering phase while the data table is iterating over each of its rows.



So in the above example, If my collections (bean.rows) has 10 items then 10 input and 10 output components will be created or only 2 components will be created.

If it creates 20 components in memory, when it is garbage collected. If I have too many components (checkbox, outputText, commandLink, commandButton - for each item) inside the datatable then it will affect the performance.

Please advice.

Thanks,
Saravanan
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic