Friday, December 23, 2011

"loaded" vs "rendered" in XPages

I couldn’t find many resources on the exact difference between loaded and rendered property available in XPage controls except for this blog by Thiyagarajan.

When you hover your mouse over loaded property it says – “Specifies whether or not the control should be created when the page is loaded.” while for rendered it says – “Indicates whether or not control should be displayed or processed on any subsequent form submission.”. Enabling the properties (exclusively) does not generate the control in the web page. But this is where the similarity ends. It was after a discussion with Sven Hasselbach on XPages forum, I understood the usage of these properties.

Create two computed fields cfLoaded and cfRendered with loaded & rendered property set to false in them respectively. Now add another computed field with following code:

If you preview the page you would get the output as:

Client ID of cfLoaded = NULL
Client ID of cfRendered = view:_id1:cfRendered

Basically, cfLoaded simply did not get created in JSF tree while cfRendered was created but was not displayed in the web page. For e.g. you can access a not rendered control during during a refresh of the XPage and set rendered to true. In contrast a not loaded control is not available and cannot be accessed programmatically. This also means that all code in a not rendered control will be internally executed. If you define a datasource in a custom control and set rendered to false, the datasource will still get computed.

Here is the complete XPage source for reference:

Update 5 Jan 2012: Declan Lynch has explained in his blog on how the use of loaded can reduce your page load time.

No comments:

Post a Comment