call a4j:commandButton from javascript on window unload

别等时光非礼了梦想. 提交于 2019-12-31 04:28:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!