2011-08-31 64 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