views:

54

answers:

1

Hello

I have a JSF web app which, after some user manipulation, opens a connection to an IBM MQ Q Manager, ie does something. When the user navigates away from the page (using FF only) or closes the browser, I would like my app to detect this and close the connection gracefully.

All I can find thus far on the web are references to window.unload and use of the body tag. I'm using RichFaces and Facelets so don't have a body tag. How can I pass word of the above event to my bean in order to get it to do work when the user leaves?

Thanks IA

EDIT Respondents BalusC and Bozho are correct - there is of course a body tag but in my case I'm not specifying it explicitly, it's being generated; my index.xhtml file contains this:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jstl/core"&gt;

<f:view>...

after which I jump straight in using a4j and rich tags etc. The questions therefore become (1): is the most efficient method to add attributes to the body tag to explicitly add a body tag with the attributes you want, or is there another way? The question exists as I did not specify a body tag explicitly in my code, but one has been generated. (2): What exactly generates the body tag in this context?

+3  A: 
  1. You do have a <body>, and you must have one
  2. Use the solution that you find, and execute your <a4j:jsFunction> on window.unload, which in turn calls the server to finalize whatever has to be finalized
  3. You'd better not rely on this - configure a reasonable connection timeout so that it can die gracefully when enough time passes.
Bozho