[ADF tip #1] Working around some clientListener limitation
- by julien.schneider(at)oracle.com
As i occasionally work on Oracle ADF, i've decided to write tips on this Framework.
Previous version of adf (10g) had a <afh:body> component to represent the body of your page which allowed to specify javascript events like onload or onunload.
In ADF RC, the body (as well as html and head) is geneated by a single <af:document>.
To implement the onXXXXX events you embed an <af:clientListener> within this <af:document> and specify property type="load" with the method to trigger.
Problem is that onunload property is not supported by th af:clientListener. So how do i do ?
Well, a solution is to add this event during page load.
First step :
Embed in your <af:document> the following :
<af:clientListener type="load" method="addOnUnload()"/>
Second step :
Add your unload event using this kind of script :
<af:document> <f:facet name="metaContainer">
<f:verbatim> <script type="text/javascript"> function addOnUnload(evt) { window.onunload=function() {
alert('Goodbye Word'); } }
</script> </f:verbatim>
When closing browser your event will be triggered as expected.