[SalesForce] Re-rendering content within Custom Component from Visualforce Page

Is it possible to re-render the content within a Custom Component from the parent Visualforce Page?

I have a custom component in an apex:outputpanel like so:

<apex:outputPanel id="popup">
    <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
        <c:BuyingJourneyStageRequirements opportunityId="{!chosenOpp}" pageControllerAttribute="{!this}" id="componentToRerender"/>
        <apex:commandButton value="Hide Pop up" action="{!closePopup}" rerender="popup,componentToRerender" oncomplete="componentRerender()"/>
    </apex:outputPanel>
</apex:outputPanel>

The Visualforce page supplies an OpportunityId and a copy of the page controller into the component, so that it can display details from the Opportunity. Clicking the "Hide Pop Up" button clears the Opp and OppId in the custom component controller and rerenders the OutputPanel.

The next time the panel is displayed (with a new OpportunityId supplied), the content of the custom component still shows the details of the previous Opportunity, which is not the desired behaviour. It's not until a link within the content within the Custom Component is clicked that the content refreshes, showing the new Opportunity details.

When I check in the debug logs, I know that the new Opportunity is being queried and returned by the controller, so the data is in place, but the re-render of the custom component content doesn't appear to be happening. Is there a way to force a refresh?

With thanks,
Andy

Best Answer

This can happen when the button that is performing the rerender contains an oncomplete attribute like you have, but does not return false. You either need to make sure that your javascript function always returns false, or simply append "return false();" to the oncomplete attribute... or remove oncomplete all together.

I've been through the same thing. The log shows perfection, screen does not update.

Current:

oncomplete="componentRerender()"

Change to:

oncomplete="componentRerender(); return false;"

You should be able to also remove the rerendering of "componentToRerender" since it's inside the popup... I bet it was just a troubleshooting step you took anyways.