aspose file tools*
The moose likes JSF and the fly likes component creation in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "component creation in JSF" Watch "component creation in JSF" New topic
Author

component creation in JSF

Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40
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}>
<hutputText value="#{item.text}"/>
<hutputText 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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40
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
 
Don't get me started about those stupid light bulbs.
 
subject: component creation in JSF