1

I have a Visualforce component, FavoritesButton, that appears in multiple places on a Visualforce Page. When you click the component, an Action Function calls the controller to update, and the clicked component rerenders. However, any copy of the component that appears elsewhere does not rerender. What would be the best way to have a component refresh (including calling a server-side function to update state) when another refreshes?

In an Aura component, I would just use an Application event that could tell all similar components to pull the latest data from the server. Is there an equivalent in Visualforce?

Here's a pared down version of my code:

Controller:

public class FavoritesButtonCntl {
    public PageReference toggleFavorite() {
        //Toggle favorite, writing to database

        return null;
    }
}

Component:

<apex:outputPanel id="favorites_button">
    <apex:actionSupport event="onclick" action="{!toggleFavorite}" rerender="favorites_button"/>
    <!-- Code to render the button. -->
</apex:outputPanel>
  • 1
    My hypothesis is that the rerender of the same ID that appears on multiple components is the issue. Try separate ids or rerender some outputPanel that wraps all the components. – cropredy Mar 30 at 4:25
  • What if I'm unable to determine every ID that would require a rerender? These buttons appear on the page dynamically, in many different locations. – Dylan Bowman Apr 2 at 16:32
  • Then rerender an ID of an outputPanel that contains all possible dynamically- created buttons. Would that work for you? – cropredy Apr 2 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.