Home > Ajax, ApEx, Javascript > Implementing session timeout in your ApEx app – Part 2

Implementing session timeout in your ApEx app – Part 2

This entry builds on the session timeout functionality described in part 1. Be sure to check that out first. In this one I describe how to get your application to popup a warning window just before a user’s session is about to timeout due to inactivity (and give them the option to remain logged in).

STEP 1 – Configure Page Zero

If you do not already have one, create a Page 0 in your application.

Add an HTML region to page 0, calling it “Session Timeout JS”.

Be sure to set its “Template” to “No Template”.

Set its conditions to be “Current Page is NOT in Expression 1” and set “Expression 1” to be the id of your user-friendly “Your session has timed out” page (Please see the previous blog entry in this series for details about this page):

Paste all of the text found in the file here into this region’s source.

When you have pasted the code, you will notice that one of the lines reads:

$x(‘pFlowId’).value+’&p_next_flow_page_sess=’+$x(‘pFlowId’).value+’:3′;

You should change the value of 3 in this line to be whatever the number of your user-friendly “Your session has timed out” page is. (Please see the previous post in this series for details about this page.)

STEP 2 – Setup the Application Process

Select Shared Components > Logic > Application Processes

And click create. Give your Application Process a name of “SET_LAST_ACTIVITY_DATE”. You must not give it a different name as this is referenced from within the javascript you pasted into the region on page zero in the previous step. Set its “Point” to “On Demand: Run this application when requested by a page process”.

Specify the “Process Text” as:

BEGIN

   APP_USERS.set_last_activity_date;

   htp.prn(‘1’);

EXCEPTION

   WHEN OTHERS THEN

      htp.p(‘0’);

END;

Step 3 – Finished. Have another cup of tea.

That’s it. Done.

If you want to test it to make sure it works (but don’t want to have to wait 18 minutes!) you could temporarily alter the timeout values in the javascript on page zero (notice below I have changed them to 1000*20 [i.e. 20 seconds] and 1000*40 [i.e. 40 seconds]).

Now log in to the application and wait.

After 20 seconds you will see a warning:

If you do nothing, after a further 20 seconds the popup will close and you will be logged out of the application.

If you click the link, the popup will close and you will remain logged in.

Advertisements
Categories: Ajax, ApEx, Javascript
  1. KK
    March 15, 2013 at 8:13 pm

    Hi Andy,

    http://andrew.tulley.co.uk/blogfiles/session_timeout_javascript.txt link is not working. Is there any other alternative link where I could see the source code?
    Please let me know. This is very critical for our business.

  2. RN
    July 25, 2010 at 3:34 am

    Thanks for the reply!

    No, I can’t see anything when clicked on this link. Its just a blank screen.

  3. Andrew Tulley
    July 23, 2010 at 9:34 pm

    RN, the Javascript is linked in the post at this URL (http://andrew.tulley.co.uk/blogfiles/session_timeout_javascript.txt). Is that not working for you?

  4. RN
    July 23, 2010 at 8:50 pm

    Can I please get the javascriptcode to use as region source? I can’t see it.

  5. Margaret Hamilton
    March 9, 2010 at 9:49 pm

    So how could implementing session timeout, as you have explained it here, be done when there is no user login? I have an open application. Not even a guest login is required.

  6. Margaret Hamilton
    March 9, 2010 at 9:48 pm

    So how could implementing session timeout, as you have explained it here, be done when there is no user login? I have an open application. Not even a guest login is required.

    I

  7. Andrew Tulley
    September 10, 2008 at 7:59 am

    MKBH,

    The server where that file sits seems to be temorarily down at the minute unfortunately. Hopefully it should be back up later. Please have a bash then.

    Andy

  8. MKBH
    September 10, 2008 at 4:24 am

    Hi,

    I can’t access your region source code:
    http://andrew.tulley.co.uk/blogfiles/session_timeout_javascript.txt

    Thanks in advanced.

    MKBH

  9. Ajay Gandhi
    August 20, 2008 at 6:42 pm

    Also, I have an embedded Mapviewer within APEX. So when I am working with MAP, and I am active on that particular page for 20 minutes, it still gives me a warning message. It means that it’s not recognizing that I am still working in the embedded window within APEX. Is there any workaround for this?

  10. Ajay Gandhi
    August 20, 2008 at 6:25 pm

    What happens if the same user logs from two different machines? In our situation, our client would like to have “Multiple Logins” at the same time. In this situation, do we have add another column in the USERS Table and capture the session_id and update that row?

  11. Andrew Tulley
    August 13, 2008 at 4:06 pm

    Pm,

    You can prevent this from happening by altering the Conditions for the region you added on Page Zero (which contains the javascript). If you have followed the instructions above the its condition should be “Current Page is NOT in Expression 1” and “Expression 1” should contain the number of the page which represents your user-friendly “Your Session Has Timed Out” page. Simply add a comma and the page number of your login page to “Expression 1” to stop the timeout popup from appearing when the user is sat on the Login page.

    E.g. “Expression 1” might now be “3,1”

    Andy

  12. pm
    June 25, 2008 at 9:33 am

    hi,

    thanks for this useful post…i was wondering is there a way to prevent appearing popup window in the login page…i dont want users redirect “Your session has timed out” page when they are in login page.

    thanks in advanced,

  1. October 30, 2008 at 8:44 pm
  2. April 4, 2008 at 11:13 am

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

%d bloggers like this: