[SOLVED] Disconnecting session when client close browser's window or tab

Hello,
I'm looking for disconnect my database session and invalidate the session with the "onunload" af:document function. I think that is the same as the "onunload" in "body" html tag.
I see some documentation about that, for example:
http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/tagdoc/core/document.html
and I see that is enable to put an EL Expression, so I try with this:
<f:view>
<af:document binding="#{backing_user.document_user}" id="document_user" onunload="#{backing_user.logout}">
<af:form binding="#{backing_user.form_user}" id="form_user"/>
</af:document>
</f:view>
and not works, then I try:
<f:view>
<af:document binding="#{backing_user.document_user}" id="document_user" onunload="return logout_function()">
<af:form binding="#{backing_user.form_user}" id="form_user"/>
</af:document>
</f:view>
and as this, I try a lot of combinations, with no result. I take my time searching in various browsers but, surprisingly, I fount not much information about this (rare, I think is a very interesting matter).
What is the way to be able this funcionallity?
Thanks,
Westh
Edit: obviusly, logout_function() is a correct javascript function :P

Hello,
I resolve my problem. Now I go to describe the steps in a little tutorial.
Remmember that this is a very basic tutorial that only allow you to do this matter, but not in deep. See bottom links for more information.
Step's list:
1) Download Shale framework from http://shale.apache.org/index.html#download
2) Import all .jar libraries in your application.
3) Open your web.xml file and add this:
<context-param>
<param-name>org.apache.shale.remoting.DYNAMIC_RESOURCES</param-name>
<param-value>/dynamic/*:org.apache.shale.remoting.impl.MethodBindingProcessor</param-value>
</context-param>
4) Consider this:
4.1) Managed bean --> userBean.java that have this method:
public void logout () {
/* Your logout code */
and this name in faces-config.xml:
<managed-bean>
<managed-bean-name>userBeanId</managed-bean-name>
<managed-bean-class>userBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
4.2) JSP Page --> home.jsp that have this code:
A clinet listener:
<af:clientListener method="unloadEvent" type="load"/>
and this javascript functions:
<f:verbatim>
<script type="text/javascript">
function unloadEvent () {
window.onunload = function () {
processUnload();
function processUnload () {
var httpRequest;
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
httpRequest.overrideMimeType('text/xml');
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
httpRequest.open('GET', 'dynamic/userBeanId/logout.faces', false);
httpRequest.send('');
function alertContents(httpRequest) {
if (httpRequest.readyState == 4) {
if (!httpRequest.status == 200) {
alert('There was a problem with the request. Http code: ' + httpRequest.status);
</script>
</f:verbatim>
Assuming the suffix '.faces' is mapped to the JSF servlet.
With this, you are able to acces to logout method of userBean (using ajax) when client closes window or tab. No servlets, no 'logout.jsp' pages, etc; and the most important thing: the code never be repeat! it's funny :)
Westh
Resources:
http://thepeninsulasedge.com/blog/2007/06/22/adf-faces-rc-more-on-javascript/
http://thepeninsulasedge.com/frank_nimphius/adf-faces-rich-client-javascript-programming/
http://www.oracle.com/technology/products/adf/adffaces/11/doc/multiproject/adf-richclient-api/tagdoc/af_clientListener.html
http://shale.apache.org/shale-remoting/apidocs/org/apache/shale/remoting/package-summary.html
http://shale.apache.org/shale-remoting/index.html

Similar Messages

  • When I close Firefox, the windows closes normally, but firefox.exe still appears in Processes in Task Manager. I have to End Process to open Firefox again, and it goes to Restore Last Session page.

    When I close Firefox, the windows closes normally, but firefox.exe still appears in Processes in Task Manager. I have to End Process to open Firefox again, and it goes to Restore Last Session page.
    Quando eu fecho o Firefox, a janela fecha normalmente, mas o firefox.exe ainda aparece no Processos do Gerenciador de Tarefas. Eu tenho que Finalizar Tarefa pra abrir o Firefox de novo, e quando abre vai para a página de Restaurar Última Sessão.

    I have the same problem - every time I close firefox (using either the red x or by selecting file ---> exit) the program appears to close normally, but the firefox.exe *32 process continues to run. If I try to re-open firefox normally I get a message that the program is still running and I need to go into task manager and manually kill the process.
    I could also kill the process from the command prompt, but both of those methods are slow and annoying. This issue has only been occurring for the last 24 hours or so; to the best of my knowledge I haven't downloaded any new software or updated any plug-ins that would have caused a switch from firefox's normal awesomeness. Norton doesn't show any new viruses or other nastiness on my computer.
    I'm running 64 bit Windows 7 Home Premium edition.

  • Call JavaScript when user closes browser containing webcenter

    Hi
    Scenario:
    1. Webcenter is opened in a browser.
    2. User closes the browser
    Requirement:
    - When user closes browser containing webcenter, a java script (or a servlet) should get called.
    As you know, we can call a script in 'onunload()' of body tag.
    But how do we call it with webcenter?
    Thanks.
    Edited by: 873687 on Dec 14, 2011 5:34 AM

    Here is a few links that I found for the JavaScript side you might play aroudn with.
    http://developer.irt.org/script/1230.htm
    http://www.webreference.com/js/tutorial1/reference.html
    http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20953676.html
    http://www.devguru.com/Technologies/ecmascript/quickref/window.html
    And two in German
    http://www.uni-magdeburg.de/service/www/books/muenz/javascript/objekte/window.htm
    http://www.exine.de/clientseitig/js_work_events.htm

  • There used to be a special feature on the previouse versions of Firefox. when you close the firefox with multiple tabs opened it displays an option of saving it or closing without saving. but this version specially the 7th doesnot have that.

    specially version 3.6 is good on saving the tabs before closing the firefox. but the latest versions should have had more that just this but it doesnt support the saving tabs or may be i didnt see it there. please if it has this feature let me know.
    the other thing is the norton toolbar 2011.7.1.3 is incompatible with firefox 7.

    Firefox 4 and later versions save the previous session automatically, so there is no longer need for the dialog asking if you want to save the current session.<br />
    Use "File > Exit" or "Firefox > Exit" (Mac: "Firefox > Quit Firefox") if you want to restore multiple windows.<br />
    You can use "History > Restore Previous Session" to get the previous session at any time.<br />
    You may need to click the orange/gray Firefox button to see History.<br />
    There is also a "Restore Previous Session" button on the default <b>about:home</b> Home page.
    Using the "Show my windows and tabs from last time" setting is a more reliable way to restore session data.
    * [http://kb.mozillazine.org/Menu_differences Firefox/Tools > Options] > General > Startup: "When Firefox Starts": "Show my windows and tabs from last time"

  • I noticed when I restart Firefox 4, it opens my previous tabs even I set the option "Open a blank page" and it opens blank page when I have "Show my windows and tabs from last time". Please ignore my question if you're already aware of this issue. Thanks.

    I noticed when I restart Firefox 4, it opens my previous tabs even I set the option "Open a blank page" and it opens blank page when I have "Show my windows and tabs from last time". Please ignore my question if you're already aware of this issue. Thanks.

    Your previous tabs will not re-open or be available to re-open when starting Firefox if:
    *your previous session was in Private Browsing mode; see --> http://support.mozilla.org/en-US/kb/Private+Browsing
    *you use Clear Recent History (''Firefox button > History > Clear Recent History'' or ''Tools > Clear Recent History''); see --> https://support.mozilla.org/en-US/kb/Clear%20Recent%20History#w_how-do-i-clear-my-history
    *you clear History automatically when closing Firefox; see --> https://support.mozilla.org/en-US/kb/Clear%20Recent%20History#w_how-do-i-make-firefox-clear-my-history-automatically
    NOTE: Your third-party Plugins (Add-ons > Plugins) are not in the "Application Basics" (Troubleshooting Information) in the "More system details" of your original post. Third-party Plugins are categorized separately in "Installed Plugins" under "More system details". You should review but not change the Plugins as detected automatically by the software on this forum when posting a question.
    If you problem still exists after checking the above, the problem could be caused by one or more of your Extensions or Plugins:
    *See --> [http://support.mozilla.org/en-US/kb/Troubleshooting+extensions+and+themes Troubleshooting extensions and themes]
    *See --> [http://support.mozilla.org/en-US/kb/Troubleshooting+plugins Troubleshooting plugins]
    *See --> [http://support.mozilla.org/en-US/kb/Basic+Troubleshooting Basic Troubleshooting]
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • When firefox starts show my windows and tabs from last time is greyed out

    firefox 4.0 startup. when I go to general under options when firefox starts show my windows and tabs from last time it is grayed out and I can't select it.

    Yes, that can happen if you run Firefox in [[Private Browsing]] mode.
    * You enter Private Browsing mode if you select: Tools > Options > Privacy > History: Firefox will: "Never Remember History"
    * To see all History and Cookie settings, choose: Tools > Options > Privacy, choose the setting <b>Firefox will: Use custom settings for history</b>
    * Uncheck: [ ] "Automatically start Firefox in a private browsing session"

  • Session does not end even when i close browser

    when i close firefox/IE the session continues ,What i need is that i am adding amount in shopping cart ,but the amount adds to old amount even when i open a new browser window ,
    i hv checked that my browser will remove cookies when i will close mozilla
    i hv also printed total=0 in servlet's ini method but the init method is called only once and total does not reset to 0,does 'th the call to init method is made everytime we start a new session via browser ,it does not get called whn i close the current browser and open new one.how to destroy the older servlet?
    I m using s=request.getSession()
    and s.setAttribute("billamnt",total)
    the code of the servlet is
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class addtocart extends HttpServlet
         HttpSession s;
         PrintWriter pw;
         int total,cam,mob;
         public void init()
              total=0;
              cam=0;
              mob=0;
              System.out.println("inside  cart init");
    public void service(HttpServletRequest req,HttpServletResponse res) throws IOException
         s=req.getSession();
        res.setContentType("text/html");
         pw=res.getWriter();
         pw.println("<html><body><a href="+"mobs"+">Mobile</a><br><a href="+"cams"+">Camera</a><form method = "+"post "+"action ="+"bill"+"><br><input type= "+"submit"+"></form></body></html>");
        if(req.getParameter("csony")!=null)
        cam=cam+Integer.parseInt(req.getParameter("csony"));
        if(req.getParameter("clg")!=null)
        cam=cam+Integer.parseInt(req.getParameter("clg"));
        if(req.getParameter("cnokia")!=null)
        mob=mob+Integer.parseInt(req.getParameter("cnokia"));
        if(req.getParameter("cerricson")!=null)
        mob=mob+Integer.parseInt(req.getParameter("cerricson"));
        s.setAttribute("cambill",new Integer(cam));
        s.setAttribute("mobbill",new Integer(mob));
        s.setAttribute("billamnt",new Integer(cam+mob));
    public void doPost(HttpServletRequest req,HttpServletResponse res)
    public void doGet(HttpServletRequest req,HttpServletResponse res)
    }Wats the problem?
    Message was edited by:
    pooja_k_online

    The servlet is not created on a session basis. All users share the same servlet object. The servlet is created once when the servlet is first called in the context, then is maintaned until the server shuts down.
    You should not store any state in the servlet. You should use the HttpSession object you get from the request object to store the totals, and all other values. You should not use the servlet to hold on to a session object, as multiple users would see the SAME session that way. If you need to use the session in multiple methods, then you should pass that object as parameter, not by making it a class member.
    You also shouldn't put the work in the service method of the HttpServlet. You should put it in either the doGet or doPost method (and if you want to make it happen for both type requests, call doPost from the doGet method and put the work in the doPost method).
    For example:
    public class ShoppingCartServlet extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request, response);
      public void doPost(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        Integer cambill = (Integer)session.getAttribute("cambill");
        int cam = 0;
        if(cambill != null) cam = cambill.intValue();
        Integer mobbill = (Integer)session.getAttribute("mobbill");
        int mob = 0;
        if(mobbill != null) mob = mobbill.intValue();
        Integer billamnt = (Integer)session.getAttribute("billamnt");
        int total = 0;
        if(billamnt != null) total = billamnt.intValue();
        String csony = request.getParameter("csony");
        if (csony != null) cam += Integer.parseInt(csony);
        String clg = request.getParameter("clg");
        if (clg != null) cam+= Integer.parseInt(clg);
        String cnokia = request.getParameter("cnokia");
        if (cnokia != null) mob += Integer.parseInt(cnokia);
        String cerricson = request.getAttribute("cerricson");
        if (cerricson != null) mob += Integer.parseInt(cerricson);
        total = cam + mob;
        session.setAttribute("cambill",new Integer(cam));
        session.setAttribute("mobbill",new Integer(mob));
        session.setAttribute("billamnt",new Integer(total));
        PrintWriter pw=response.getWriter();
        pw.println("<html><body><a href="+"mobs"+">Mobile</a><br><a href="+"cams"+">Camera</a><form method = "+"post "+"action ="+"bill"+"><br><input type= "+"submit"+"></form></body></html>");
        pw.close();
    }Message was edited by:
    stevejluke

  • RMI-Server "checks" when Client closes RMI-Connection

    Hi there!
    I hope somebody can help me...
    I'm developing a client/server application where my client calls a remote method and my server starts working (i.e. 5-7 minutes batch processing).
    Is there a way my server "gets informed", when RMI connection is closed (network failure, client closes)? In this situation the server should perform a rollback, delete generated files, etc.
    I don't know if there is thrown a exception inside the server method, which I can catch ....
    Any suggestion is welcome ..
    Best Regards
    Anton

    Thanks a lot, I will have a look at the tutorial.
    Initially my thoughts on this issue were:
    -) The Client-RMI call is made in an own Thread (There are several things to do before job processing can start on the remote machine).
    -) when the RMI call is processed, the thread gets blocked, so doesn't add load to the machine (hope so).
    -) RMI does the "alive-checking", when network connection fails the client can mark the job as failed. The called server should also do some rollback. So I do not have to implements callback-listeners to react on server callbacks
    -) But I'm worried about open connections, running out of socket resources and that there is no way to abort a endless running job.
    This is my first aproach to solve this problem, I would be very glad about any comment ...

  • How to capture when user closes browser

    I am implementing a scenerio where I need to reset login status in the database to false when a user closes browser without logout. I am at fix, how do I do that ????? With the java script solution, its a browser dependent and may not work with all the browser. With java sessionListener, the sessionDestroyed() method is never called when browser is closed.
    Plz. help... how can I capture the browser closing event. My application is running on Websphere and integrated with active directory for authentication and authorization.
    Thanks in advance......

    SoulTech2012 wrote:
    what about HttpSessionBindingListener?
    javascript solution doesn't sound good to me"hack" was chosen for that reason. Currently, there are no real good solutions for this. The browser runs autonomously from the server so there is not a lot that can be done. HttpSessionBindingListener is intriguing but I bet when the browser is x'd out of there is nothing sent to listen to.
    The first reply "reasonable timeouts" is the most relied on solution. All others are a lot of work for iffy pay back at best. This is one of the issues that has forced me into rather strict no session solutions.

  • [SOLVED] Run xscreensaver when I close the laptop lid

    I have xscreensaver running in my archlinux, and with a systemd service, I can start it after waking up my laptop.
    The problem is that I like to keep my laptop running when I close the lid (for example, to go to bed while I'm downloading a file, I like to simply close my lid), but I want to lock my computer.
    In the /etc/systemd/logind.conf, there is a nice option called HandleLidSwitch, which specifies which action is invoked when the lid is closed, and there is a lock option, but It doesn't work for me.
    The option suspend works fine.
    Here is my /etc/systemd/logind.conf:
    # This file is part of systemd.
    # systemd is free software; you can redistribute it and/or modify it
    # under the terms of the GNU Lesser General Public License as published by
    # the Free Software Foundation; either version 2.1 of the License, or
    # (at your option) any later version.
    # See logind.conf(5) for details
    [Login]
    #NAutoVTs=6
    #ReserveVT=6
    #KillUserProcesses=no
    #KillOnlyUsers=
    #KillExcludeUsers=root
    #Controllers=
    #ResetControllers=cpu
    #InhibitDelayMaxSec=5
    HandlePowerKey=suspend
    #HandleSuspendKey=suspend
    #HandleHibernateKey=hibernate
    HandleLidSwitch=ignore
    #PowerKeyIgnoreInhibited=no
    #SuspendKeyIgnoreInhibited=no
    #HibernateKeyIgnoreInhibited=no
    #LidSwitchIgnoreInhibited=yes
    #IdleAction=ignore
    #IdleActionSec=30min
    Any help?
    Last edited by alomsimoy (2013-09-10 18:08:33)

    I would say that you should just have logind ignore the LidSwitch altogether.  So if it is set to ignore the lid switch, then it obviously isn't going to be entering the suspend.target (or is it the sleep.target, I can't remember).  Therefore, you are going to have to have some other way of triggering actions in response to these events.
    The lid switch sends an event to udev, so you have the option of having a udev rule that responds to this, or using acpid to start this for you.  I would recommend using acpid, as it is much more flexible in what it can allow you to do.
    Edit: acpid is not necessarily more flexible than a udev rule, as it relies on the udev events.  But it is a much easier method of setup since it simply relies of basic scripting in order to make it work.  It can allow for one central script (or collection of scripts) to handle all the different events that udev sends.  To see what kinds of things trigger a udev event, you can use udevadm monitor or if you install acpid, there is the acpi_listen option.
    Edit2:  BTW, what is it you mean by not working?  Does it still suspend on lid close, or is your xscreensaver not started?  You need to be more explicit there.  If it is still suspending, have you rebooted or restarted logind after making those changes to logind.conf?  You can't just edit the file and have the changes implemented right away, as the configuration is parsed and the settign implemented on the service start.
    Last edited by WonderWoofy (2013-09-10 17:28:05)

  • Close browser by closing last tab

    I would like my browser to close when I close the last tab. I tried browser.tabs.closeWindowWithLastTab;true but when rightclicking the last tab, "close" is grayed out.

    You can't close the last tab via the right-click context menu or via a middle-click if browser.tabs.closeWindowWithLastTab is true.<br />
    If the pref is false then you can close the tab, but not the window.
    You can only close the last tab and window via the Ctrl+W shortcut.<br />
    Via the menu only Quit or Exit is available unless you open the File menu via the Alt+F shortcut and then you see Close Tab.

  • Firefox 3.6.3 closes the first window when I close the 2nd window

    Firefox 3.6.3 seems so buggy. When I have 2 windows open and I close the 2nd one, the first one also closes. When I open a new window, it sometimes shows up minimized in the top left corner.
    == This happened ==
    Every time Firefox opened
    == I started using FF 3.6.3

    See http://kb.mozillazine.org/Firefox_crashes and [[Firefox crashes]]
    Set the pref [http://kb.mozillazine.org/browser.sessionstore.max_resumed_crashes browser.sessionstore.max_resumed_crashes] to '''0''' on the '''about:config''' page to get the about:sessionrestore page immediately with the first restart after a crash has occurred or the Task Manager was used to close Firefox.
    See https://wiki.mozilla.org/Session_Restore#Preferences
    http://kb.mozillazine.org/Browser.sessionstore.max_resumed_crashes
    See also http://kb.mozillazine.org/Session_Restore#Firefox_keeps_crashing_after_restoring_a_session

  • Wrong Font when client operating system is Windows 98

    My application using font Tahoma (Nomarly, I run on Windows 2000 Advance Server). But When I runing from a client machine that use Windows 98, Application font is wrong. I know Windows 98 don't support unicode. How will I do to use my application on Win98 OS.
    Help me,plz!

    Hi Members,
    Sorry, I haved tried following below instructions but I was successfull. Can you show me more detail,plz. For example, I want to map font tahoma to times new roman to run application (Oracle Form 9i)in Windows98 OS.
    Give me somes helps, plz.

  • How do you close only one window (not tab) when you have two open?

    I can close a tab when I have multiple ones open but if I have two windows open and I close one window it closes all other windows. How can I close just one window without shutting down any other windows?

    Yes, when I click on the red X it closes both windows. I'll try the Ctrl+w
    Thanks

  • Safari crashes when I close the app window

    Everytime I close an safari window ( + w or hit the cross) the app crashes. Does anyone know this issue? I have an mile long crash report if that helps anyone in here, but I wouldn't want to spam such a long report, if it doesn't help..

    Hi Hanze,
    I have an mile long crash report if that helps anyone in here, but I wouldn't want to spam such a long report, if it doesn't help..
    Please post it.

Maybe you are looking for

  • Time machine screwed up my external hard drive

    Hey. Just bought a seagate goflex external hard drive and connected it to my macbook pro. Time machine reformatted it then began to back up my data, which was 40GB large (just bought the macbook pro 3 days ago), but then my seagate started making a w

  • How can I change the measurement of the kerning quick key? (When you press option + arrow keys)

    Right now when I am using the quick keys to kern type, everything jumps too far. I want to lower the measurement or unit that it moves when I use this, as it is currently driving me nuts.

  • What's with this website?

    I've been having a heck of a time viewing this Discussions forum for the last couple of weeks. The window looks fine when I first log on as a guest. But as soon I log on under my own account, it goes haywire. The first screen I get after I log in as

  • AIX 5L's HACMP on Database Servers

    Hello everyone, I've been looking around for information on a 4 node SAP ERP/Oracle RAC architecture for AIX 5L and I'm being constantly lead to vendors being responsible for the clustering requirements. I'm trying to setup a 4-server ERP architectur

  • Syntax for href tag in out.println

    Hi, In the jsp, the table displays document number from the for loop in it. I'm trying to put a hyperlink using href tag to the document number which is in the value "table.getString("VBELN")" out.println(var + table.getString("VBELN")); I do not kno