2011-08-31 62 views
0

a4j:commandLink移植到h:commandButton问题。JSF:JS重定向不适用于h:commandButton onclick事件

这方面的工作情况:

<a4j:commandLink event="onclick" onclick="if (!confirm('#{resourceBundle.agreement_cancel_message}')) return false;" oncomplete="window.location.href='menu?agreementId='+ agreementId;"/> 

这种情况下,与h:commandButton不起作用,当前页面刷新刚:

<h:commandButton onclick="if (!confirm('#{resourceBundle.agreement_cancel_message}')) return false;window.location.href='menu?agreementId='+ agreementId;"/> 

据我所知,我不能为h:commandButton使用oncomplete在所有。

回答

0

页面被刷新,因为输入的默认事件处理程序正在工作。

尝试防止输入的提交行为(返回false;末):

<h:commandButton onclick="if (!confirm('#{resourceBundle.agreement_cancel_message}')) return false;window.location.href='menu?agreementId='+ agreementId; return false;"/> 
3

您需要总是return false为了防止按钮的默认操作(提交表单)。

<h:commandButton onclick="if(confirm('#{resourceBundle.agreement_cancel_message}'))window.location.href='menu?agreementId='+ agreementId;return false;"/> 

(把{}围绕if体可以提高可读性)

顺便说一句,你似乎永远不会调用bean的操作方法。为什么你根本用<h:commandButton>

<button onclick="if(confirm('#{resourceBundle.agreement_cancel_message}'))window.location.href='menu?agreementId='+ agreementId;return false;"/> 
+0

怎么说,因为它就像我们的项目的政策 - 降低A4J:命令*使用 – sergionni

+0

进一步我要inoke通过的commandButton – sergionni

+0

豆的方法,因为你改变当前这是不可能的由JS定位。 – BalusC