问题
I am not able to call a4j:commandButton
click on window unload. my jsf code is here
1st the javascript
in which i have window unload method and i have called button click in that function.
<script type="text/javascript">
window.onbeforeunload = function() {
document.getElementById('pForm:closeTime').click();
}
</script>
2nd i have hidden a4j:commandButton
in body
<h:form id="pForm">
<a4j:commandButton id="closeTime" value="" action="#{controller.update}" oncomplete="javascript:window.close()" style="visibility:hidden;display:none" </a4j:commandButton>
</h:form>
when window is closed this controller is not getting called. Help me out in this !!!
回答1:
It's much cleaner to use jsFunction
for this:
<script type="text/javascript">
window.onbeforeunload = function() {
closeTime();
}
</script>
<h:form id="pForm">
<a4j:jsFunction name="closeTime"
action="#{controller.update}"
oncomplete="window.close()"/>
</h:form>
来源:https://stackoverflow.com/questions/23101081/call-a4jcommandbutton-from-javascript-on-window-unload