Skip to content

APEX Tip: Page Auto Refresh

October 25, 2006

This tip provides your users with the option of choosing a refresh interval for the page. The following steps were tested with Apex version 2.2 but should work on earlier versions of Apex or HTMLDB.

  1. Create an Application Item to store the current refresh interval (e.g. F100_REFRESH_INTERVAL)
  2. Create an Application Computation to initialise it (e.g. F100_REFRESH_INTERVAL_COMP):
    • Computation Item = F100_REFRESH_INTERVAL
    • Computation Point = On New Instance (e.g. On Login)
    • Computation Type = Static Assignment
    • Computation = (default number of seconds, e.g. 60)

  3. Create a static List of Values (e.g. REFRESH_INTERVAL):

Display – Return
1 sec – 1
5 sec – 5
10 sec – 10
30 sec – 30
1 min – 60
5 min – 300
(you can change this list how you like, as long as the return values are positive integers)
(it is probably not a good idea to provide zero seconds as an option, as this will cause the page to continually refresh without giving the user much chance to intervene)

Now, for each page you wish to have auto-refreshed, edit the Page Properties:

  • HTML Header = <meta http-equiv="refresh" content="&F100_REFRESH_INTERVAL.">

Somewhere in your application you will want to provide the user with a way of modifying the refresh rate. I prefer to provide this on the same page that is auto-refreshed.
Create an Item (e.g. P1_REFRESH):

  • Display As = Select List with Submit
  • Region = (any region, I prefer the Breadcrumb region if one exists)
  • Label = Refresh
  • Source Used = Always, replacing any existing value in session state
  • Source Type = Item (application or page item name)
  • Maintain session state = Per session
  • Source value or expression = F100_REFRESH_INTERVAL
  • List of Values definition = REFRESH_INTERVAL

I also like to show the date/time when the page was last refreshed. To do this, I just add a display-only text item to the page with:

  • Source Used = Always, replacing any existing value in session state
  • Source Type = PL/SQL Expression or Function
  • Maintain session state = Per session
  • Source value or expression = TO_CHAR(SYSDATE,'Dy DD Mon HH24:MI:SS')

Now, the page will be auto-refreshed according to the default interval, and the user can change the refresh interval using the select list.

You can add the item and the auto-refresh header to any page you like. If you need a different refresh interval on different pages, you will need to create additional Application Items, along with their own Application Computations to initialise them.

If the user hits the “Stop” button in IE, the page seems to stop auto-refreshing. I don’t know if this feature works the same in other browsers, however.

About these ads

From → APEX

6 Comments
  1. This tip is really helpful in my project, thanks !

  2. Mette Stephansen permalink

    Hi there

    I have an application with this style refresh – and I discovered just 10 min ago, that the app runs a pl/sql procedure depening on the REQUEST value .. .so now this procedure har made lots of inserts (every 3 minutes).

    How will I best solve that problem? I’m on Apex. 4

    regaards
    Mette

  3. Hi Mette,

    Having an auto-refresh on the page is no different (from Apex’s point of view) than if the user manually refreshed the page. What do you do now, if the user manually refreshes the page?

    I would suggest you remove the procedure that’s doing the insert on each refresh, if that’s not what you want.

    If the user’s first visit to the page must do the insert, you could create a separate “landing” page, which does the insert, then automatically redirects to the refreshable page.

    I hope this helps.

    Jeff

  4. Bipul permalink

    Thanks.

    or whatever value in HTML header works :-)

  5. Hi Jeff:

    Hope you could help me out, followed your steps but every time I change the refresh interval using the select list, after submit it gets to the previously set value, i.e. I set the default application item to 150 seconds, so the select list shows 2,5 minutes, when I change it to 5 secs, after it gets reloaded the select list gets back to 2,5 minutes.

    Any ideas?

    Thanks a ton in advance.

    Leo.

    • Not sure, Leo. The way it is supposed to work is that when your page is Submitted, the page-level item’s value is copied back to the application-level item (F100_REFRESH_INTERVAL). Maybe something else on your page is interfering with the Submit processing? Have you tried it in a blank application with an ordinary page?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 200 other followers

%d bloggers like this: