Andy’s Blog: Application Express etc.


Implementing session timeout in your ApEx app – Part 2

Posted in Ajax, ApEx, Javascript by Andrew Tulley on April 3, 2008

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.

8 Responses to 'Implementing session timeout in your ApEx app – Part 2'

Subscribe to comments with RSS or TrackBack to 'Implementing session timeout in your ApEx app – Part 2'.


  1. [...] app – Part 3 This entry builds on the session timeout functionality described in part 1 and part 2. Be sure to check those posts out [...]

  2. Andrew Tulley said,

    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

  3. MKBH said,

    Hi,

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

    Thanks in advanced.

    MKBH

  4. Ajay Gandhi said,

    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?

  5. Ajay Gandhi said,

    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?

  6. Andrew Tulley said,

    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

  7. pm said,

    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,


  8. [...] Next time I’ll write about how we can make an ApEx application popup a message just before a user’s session is about to time out, giving them the option to remain logged in. You can now see the second part here. [...]


Leave a Reply