+ Start a Discussion
Shravya Rama 9Shravya Rama 9 

A method is getting called unnecessarily

For some reason, getmycust() method is getting called as soon as the page loads. Can somebody please tell me where am I going wrong.
<apex:page standardController="Reservation__c" extensions="CarSharingClass">

<apex:commandButton value="Show Fahrzeuge"  action="{!showPanel}" / >

// I want to show the table only when the button is clicked.

<apex:pageBlockTable value="{!myCust}" var="showFahr" rendered="{!If(myCust != null && myCust.size>0 && isRendered==true ,true,false)}"  >

public class CarSharingClass {

 public PageReference showPanel(){
        isRendered = true;
        return null;
    public List<Fahrzeuge__c> getMyCust() { 



It is being called because it is a getter for a value on the page. Your markup of '{!myCust}' translates server side to invoking 'getMyCust', so in order to render the page the VF engine has to invoke your method.
Shravya Rama 9Shravya Rama 9
Is there anyother alternative not to call that method in the begining.