[英]unexpected whole page refresh using p:commandButton
I am using below code to delete the row in p:datatable
. 我正在使用下面的代码删除
p:datatable
的行。 If am using onclick method inside p:commandbutton
tag it refresh whole page else its working fine. 如果在
p:commandbutton
标记内使用onclick方法,则刷新整个页面,否则工作正常。 please Give me some solution. 请给我一些解决方案。
<p:commandButton title="Delete Affiliation" immediate="true" process="@this"
update="affiliationList" alt="Delete Affiliation" icon="ui-icon-trash"
action="#{readAuthorDetailsbean.deleteSelectedAffiliation}" style="width:30px"
onclick="return confirm('Are you sure, Do you want to delete this record?');">
<f:setPropertyActionListener value="#{affiliation}"
target="#{readAuthorDetailsbean.selectedAffilliationListAL}" />
</p:commandButton>
If you rephrase your onclick
attribute to 如果您将
onclick
属性改为
if (!confirm('Are you sure, Do you want to delete this record?')) return false;
then it should work as expected. 那么它应该会按预期工作。 What it does is:
它的作用是:
false
and further processing is aborted. false
并且中止进一步的处理。 If you just do return confirm('Are you sure?')
and user is sure, the returned true
value cancels PrimeFaces added return false
at the end of the onclick
attribute (it does that for ajax) and instead of ajax request you see normal post submission (page reload). 如果您只是
return confirm('Are you sure?')
并且用户确定,则返回的true
值会取消PrimeFaces在onclick
属性末尾添加的return false
(它对ajax起作用),而不是ajax请求,您会看到正常提交后(重新加载页面)。
return false
cancels default behavior of html elements . return false
取消html元素的默认行为 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.