0

I have a complex page with multiple custom components on it, each with their own controller. I'm finding that when I do a partial rerender in one of the custom components, the getters in the apex controllers for the other custom components are being called (almost like they're re-rendering and calling their controllers for values, etc.)

I just wanted to check that this isn't expected behaviour. I've not worked in a scenario with multiple controllers on a page due to multiple custom components in my recollection, so am not sure if this is something that should be happening. There's probably a performance hit here, as it's doing a bunch of recalculation that it shouldn't need to be doing.

1 Answer 1

1

I decided to test this out by creating a new component:

<apex:component controller="TestComponentController">
    <apex:outputText value="{!currentDateTime}" />
</apex:component>

With the following Controller:

public with sharing class TestComponentController {
    public DateTime currentDateTime {
        get;
        set;
    }
    public TestComponentController() {
        currentDateTime = System.now();
    }
}

Finally, in a Visualforce Page:

<apex:form>
  <apex:outputPanel id="testpanel">
    <c:testComponent />
  </apex:outputPanel>
  <apex:commandButton reRender="testpanel" />
</apex:form>

The idea was that if reRendering did refire the constructor, the DateTime would change accordingly.

It didn't.

So with respect to your comment:

I just wanted to check that this isn't expected behaviour

Something else must be doing something that makes it look like it's firing the constructor again, or something is actually firing the constructor.

1
  • Thank you - subsequent to my posting the comment, I wrote a simple page with a couple of components with various command buttons and partial refreshes which included variables within them. I found that the variable getters were only fired when I was explicitly refreshing areas of the page that included them, so my findings agree with yours. Thank you for taking the time to look into this! I will report back here if I find what's going on, just for completeness.
    – Bigears
    Commented Nov 22, 2016 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .