开发者

JSF: JS redirection doesn't work for h:commandButton onclick event

Migrating from a4j:commandLink to h:commandButton problem.

this working case:

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

this case with h:commandButton doesn't work,current page just refreshed:

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

As I know,I can't use oncomplete for h:commandButton at all.


You need to always return false in order to prevent the button's default action (submitting the form).

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

(putting {} around the if body may improve readability)

By the way, you seem to never invoke a bean action method. Why are you using <h:commandButton> at all?

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


Page is refreshed because default event handler of input is working.

Try preventing input's submit behavior (return false; at the end):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜