簡體   English   中英

使用p:commandButton意外刷新整個頁面

[英]unexpected whole page refresh using p:commandButton

我正在使用下面的代碼刪除p:datatable的行。 如果在p:commandbutton標記內使用onclick方法,則刷新整個頁面,否則工作正常。 請給我一些解決方案。

<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>

如果您將onclick屬性改為
if (!confirm('Are you sure, Do you want to delete this record?')) return false;
那么它應該會按預期工作。 它的作用是:

  • 如果用戶確認它沒有返回值並且PrimeFaces可以進一步處理AJAX請求
  • 如果用戶取消確認,則返回的值為false並且中止進一步的處理。

如果您只是return confirm('Are you sure?')並且用戶確定,則返回的true值會取消PrimeFaces在onclick屬性末尾添加的return false (它對ajax起作用),而不是ajax請求,您會看到正常提交后(重新加載頁面)。
return false取消html元素的默認行為

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM