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
saharisahari 

how to refresh the vf page automatically for every 5 min

I have a Vs page that tracks Planes on the Google earth. 

The users would like to have it open all day.

So I need to keep this page refreshing every 5 min or so.

 

Does anyone have an idea as to how to achieve this functionality? Any help would be greatly appreciated.

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

All the Apex is eventually generating HTML.  So, you can use the Meta tag.

 

 

<apex:page>
	<html>
		<head>
			<META http-equiv="refresh" content="5">
		</head>
	</html>
	From Apex tags:
	<apex:outputText value="The formatted time right now is: {0,date,yyyy.MM.dd G 'at' HH:mm:ss z}">
		<apex:param value="{!NOW()}" />
	</apex:outputText>
</apex:page>

 

Except use 300 for five minutes instead of 5 seconds as I've got there.

 

Best, Steve.

 

All Answers

bob_buzzardbob_buzzard

You can use an actionPoller component for this.

 

 

<apex:actionPoller interval="300" status="state"/>
<apex:actionStatus id="state" startText="Refreshing" stopText=""/>

 

 

SteveBowerSteveBower

All the Apex is eventually generating HTML.  So, you can use the Meta tag.

 

 

<apex:page>
	<html>
		<head>
			<META http-equiv="refresh" content="5">
		</head>
	</html>
	From Apex tags:
	<apex:outputText value="The formatted time right now is: {0,date,yyyy.MM.dd G 'at' HH:mm:ss z}">
		<apex:param value="{!NOW()}" />
	</apex:outputText>
</apex:page>

 

Except use 300 for five minutes instead of 5 seconds as I've got there.

 

Best, Steve.

 

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

You can use <apex:actionPoller> to refresh the page on a defined interval. A timer that sends an AJAX update request to the server according to a time interval that you specify. The update request can then result in a full or partial page update.

 

Go through the sample code given below :

 

/***  Visualforce : ***/ 

 

<apex:page controller="exampleCon">
    <apex:form>
        <apex:outputText value="Watch this counter: {!count}" id="counter"/>
        <apex:actionPoller action="{!incrementCounter}" rerender="counter" interval="15"/>
    </apex:form>
</apex:page>


Did this answer your question? if so, please mark it solved.           
           
/***  Controller: ***/ 
   
           
public class exampleCon {
    Integer count = 0;
           
    public PageReference incrementCounter() {
        count++;
        return null;
    }
           
    public Integer getCount() {
        return count;
    }
}

 

Did this answer your question? if so, please mark it solved.

<apex:page controller="exampleCon">
<apex:form>
<apex:outputText value="Watch this counter: {!count}" id="counter"/>
<apex:actionPoller action="{!incrementCounter}" rerender="counter" interval="15"/>
</apex:form>
</apex:page>


/*** Controller: ***/ 


public class exampleCon {
Integer count = 0;

public PageReference incrementCounter() {
count++;
return null;
}

public Integer getCount() {
return count;
}
}
saharisahari

Thank you all for the immediate replies. It works now.