Click af:commandButton from javascript
814457Jun 20 2011 — edited Jun 20 2011Hey
I'm having the same issue as you. I want my session to be destroyed when a users closes the window.
As onUnload triggers every time you navigate away from the page I can't use it. Instead I'm using the following Js code:
<script type="text/javascript">
window.onbeforeunload=function(){
if (window.event.clientY < 0 && (window.event.clientX > (document.documentElement.clientWidth - 5) || window.event.clientX < 15) ) {
document.getElementById('hiddenButton').click();
}
}
</script>
my af:commandButton has the following structure :
<af:commandButton text="" id="hiddenButton"
onclick="if (confirm('#{res['sag.generales.cerrarSesion']}')) {window.document.all['logoutFrame'].src='../servlet/LogoutServlet';window.setTimeout('closeWindow()',100);}"/>
<af:regionDef var="attrs">
But is sadly not working. When I close the page nothing executes.
On the other hand if I use a regular button instead of an commandButton I'm able to click it via javascript
<input type="button" name="theSubmitButton" id="hiddenButton" value="Button" onclick="alert('The button was clicked.');"/>
i mean, in this case when i close the window i get the message "The button was clicked". But if I use the same code I have on the af:commandButton onclick for closing my session nothing happens.
I'm super new to adf and java so maybe I'm missing something obvious.
Thanks a lot for your hepl. I mean it :)
Edited by: loskiorama on Jun 20, 2011 8:54 AM