You need to sign in to do that
Don't have an account?
Tan J
Is apex getter method runs only once regardless of how many times it is called on VF page?
I have a basic question. I have a big VF page with many sections which render/hide based on some flags. The flags are set in constructor of controller extension and are mostly depend on the logged-in user profile, role etc. (i.e. they do not change value). Now I am trying to make my constructor thin and move these flags outside it in getter/setter methods. However, I want to know if these getters will always be called when they are referenced in 'rendered' on multiple sections etc. (i.e. the flags are referred in VF page multiple times). When I did some testing, it looks like they are called only first time but want to confirm my understanding. With the flags being set in constructor, I am assured that they will run only once when the page loads. But I want to reduce the code in constructor.
It's possible that getter method may be exceuted multiple times.Let's say that the VF page has link or button (CommandButton) and on clicking a controller method is called.In this case getter method is called once again before the page loads.That's why one of VF page best practices is to avoid SOQL within getter method. It degrades the performance of the page.
Avoid SOQL queries in your Apex controller getter methods.
In your case, if the flags need to be set only once in the page and these remains constant throughout the interaction in the page, these should be initialized inside the controller.
Please let me know if you get any helpful information on this.
Regards,
Shashi
All Answers
If your getter variables are dependent on each other, it may lead to issue. Here is an interesting topic on this -
http://www.tehnrd.com/getter-method-order-and-visualforce-pages/
Regards,
Shashi
It's possible that getter method may be exceuted multiple times.Let's say that the VF page has link or button (CommandButton) and on clicking a controller method is called.In this case getter method is called once again before the page loads.That's why one of VF page best practices is to avoid SOQL within getter method. It degrades the performance of the page.
Avoid SOQL queries in your Apex controller getter methods.
In your case, if the flags need to be set only once in the page and these remains constant throughout the interaction in the page, these should be initialized inside the controller.
Please let me know if you get any helpful information on this.
Regards,
Shashi
There are two ways: 1) Use constructor or 2) use getter/setter properties with lazy initialization. I am going to implement the second way simply because I want less code in constructor. Please share your thoughts.
Additionally, you can enable developer mode and View View state flag to monitor your VF page for performance.
Regards,
Shashi