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:
<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;"/>
精彩评论