[英]Abort long ajax call from a commandButton actionListener?
我希望能夠停止執行以commandButton開始的冗長任務 :
<p:commandButton id="startBatch"value="Go" actionListener="#{batchController.sendBatch()}"ajax="true" />
因此,在我的模型中,我添加了一個布爾“ abort”,並且在sendBatch()內部添加了一個檢查,以在布爾變為真時停止循環:
for (int i = 1; i <= batch.size(); i++) {
if (batchModel.isAbort()) {
break;
}
}
在我的XHTML中,我添加了一個新按鈕,該按鈕調用將此布爾值設置為true的方法:
<p:commandButton id="abortBatchButton"
value="Abort"
actionListener="#{batchController.abort()}"
ajax="true"/>
問題在於sendBatch()方法完成后將調用abort()。
有一個簡單的方法來實現嗎?
默認情況下, p:commandButton
使用Ajax。 但是,默認情況下,多個操作(請求)會排隊並同步執行。 因此,如果您開始執行冗長的操作,則在完成前一個操作后,將處理下一個操作。
如果您不想將操作排隊,則應在相應的按鈕上使用async="true"
。
在您的情況下:
<p:commandButton id="startBatch"
value="Go"
async="true"
actionListener="#{batchController.sendBatch()}" />
我已經刪除了ajax="true"
,因為它是默認值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.