function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AidanAidan 

Rerendering a list using a standard controller

Hi all,

 

I'm trying to have a list of Opportunities that will automaticallly refresh after a timeout. I've looked into the actionPoller element as a way to implement this, but it isn't behaving as I would expect. I can see that my pageblock is being re-rendered as I have put the current time in there and it does change. But, the list that I want to rerender doesn't respond to changing data.

 

My guess is that the recordset is fetched once and rerendering doesn't make it requery. But I'm a bit new to Visualforce, so any insight into the mechanisms and/or tips on how to get the list to update fully would be much appreciated.

 

My simple code:

 

<apex:page standardController="Opportunity" recordSetVar="opp" sidebar="false" showheader="false" >
 <apex:form >
  <apex:pageBlock id="mainList">
   {!NOW()}
    
   <apex:pageBlockTable value="{!opp}" var="o" id="theList">
    <apex:column value="{!o.name}"/>
    <apex:column value="{!o.account.Name}"/>
    <apex:column value="{!o.closedate}"/>
   </apex:pageBlockTable>      
  </apex:pageBlock>

  <apex:pageBlock >
   <apex:actionPoller reRender="mainList" interval="5"/>
  </apex:pageBlock>
 </apex:form>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You are correct that the underlying records supplied by the controller won't be updated.  There's a couple of options to achieve this - one is to write a custom/extension controller, while the other is to add a javascript timeout that refreshes the entire page.  If it were me, I'd go with the latter as its not very much work at all, and there's no need to write a controller class.  The downside is that the browser reloads the entire page, which isn't as slick as a rerender.

All Answers

bob_buzzardbob_buzzard

You are correct that the underlying records supplied by the controller won't be updated.  There's a couple of options to achieve this - one is to write a custom/extension controller, while the other is to add a javascript timeout that refreshes the entire page.  If it were me, I'd go with the latter as its not very much work at all, and there's no need to write a controller class.  The downside is that the browser reloads the entire page, which isn't as slick as a rerender.

This was selected as the best answer
AidanAidan

Nice one, Bob - No need to keep banging my head against that one any more :)

 

I think I'll have to write a controller as the context is within a Home Page Component on the homepage and we don't want to refresh the whole thing.

bob_buzzardbob_buzzard

I reckon you'll be okay there - its actually very difficult to refresh the whole thing, as VF pages come from a different server so the browser can decide its a cross site scripting attack.  You should just be able to ask your window to refresh I would think.  That said, if you go the controller route it will be slicker and there won't be blank pages to confuse the users.