Apex:Component页面重渲染后无法刷新的技术问题求助
Hey there, let's tackle this frustrating rerendering problem with your Apex Component. It sounds like you've tried all the usual tricks—rerendering panels, page reloads, timeouts—but nothing sticks until you hit that browser refresh button. Let's break down the likely causes and fixes tailored to your code:
Common Culprits & Fixes
1. Rerender Targets Are Missing the Component's Container
Looking at your code, your <c:mySidebar> sits directly inside the <apex:define> block, but Visualforce can be finicky with IDs in composition structures. Wrapping the component in a dedicated output panel with a clear ID will make rerendering more reliable, as it gives you a precise target to trigger:
<apex:define name="sidebar" > <apex:outputPanel id="sidebarContainer" layout="block"> <c:mySidebar id="theSidebar" applicationCurrentStage="{!currentStage}" applicationMaxStage="{!app.Application_Stage__c}" stages="{!appPagesMetadata}" memberSegmentedStages="{!memberSegmentedStages}" stagesToInvalidate="{!stagesToInvalidate}" currentMemberIndex="{!memberIndex}" members="{!members}" application="{!app}"/> </apex:outputPanel> </apex:define>
Then update your command buttons to rerender this specific container instead of the entire page:
<apex:commandButton action="{!save}" value="{!$Label.Save_Progress}" rerender="sidebarContainer" rendered="{!app.Application_Stage__c==NEW_STAGE && !guestUser}" oncomplete="myJS.afterSave({!isSaved},false);" status="blockStatus" />
2. Controller Variables Aren't Being Updated Properly
For the component to refresh, all variables it binds to (like currentStage, app.Application_Stage__c, memberIndex) need to be explicitly updated in your server-side action methods (e.g., save, saveAndNext). Double-check that these methods modify the variables and persist changes to related records:
public PageReference saveAndNext() { // Save your application record first update app; // Update the stage variables that drive the sidebar currentStage = app.Application_Stage__c; // Update any other bound variables (memberIndex, stagesToInvalidate, etc.) return null; // Keep the page context for rerendering }
If these variables aren't updated on the server, the component will just show old values even after rerendering.
3. Component Caching or Static Variables
If your <c:mySidebar> has its own controller, avoid using static variables to store dynamic data—static variables persist across requests in the same session, causing the component to retain stale data. Instead, use instance variables that pull values directly from the component's attributes:
// Bad: Static variable caches old data // public static String applicationCurrentStage; // Good: Instance variable bound to component attribute public String applicationCurrentStage { get; set; }
4. Browser Caching of Component Resources
If even full page reloads don't update the component, browser caching might be the issue. Add a dummy "cache buster" attribute to your component that changes on every request—this forces the browser to fetch the latest version:
<c:mySidebar id="theSidebar" cacheBuster="{!System.now().getTime()}" <!-- Random value on each request --> applicationCurrentStage="{!currentStage}" ... />
You don't need to use this attribute in the component itself; it just tricks the browser into not serving cached content.
5. ActionFunction Rerender Scope
Your goToPage action function only rerenders fastRerenderPanel (which is empty). If navigating via the sidebar should update the component, add sidebarContainer to its rerender list:
<apex:actionFunction action="{!findPage}" name="goToPage" status="blockStatus" reRender="fastRerenderPanel, sidebarContainer" oncomplete="redirectToPage();"> <apex:param name="goToPage" id="goToPage" assignTo="{!goToPage}" value="" /> <apex:param name="memberIndexNavigation" id="memberIndexNavigation" assignTo="{!memberIndex}" value="" /> </apex:actionFunction>
Final Checks
- Ensure no bound variables are marked as
transient(unless intentionally excluded from view state)—transient variables won't persist across requests, so their values won't update during rerenders. - Use your browser's developer tools to inspect the Visualforce AJAX response. If the updated component markup isn't present, the server isn't sending new data, pointing to a controller logic issue.
Hope these fixes get your component rerendering properly without needing manual browser refreshes!
内容的提问来源于stack exchange,提问作者Mike

