2013-07-01 99 views
0

我一直在試圖將一個隊列放到文本區域,並且它不合作。我將在下面列出相關的代碼部分。Richfaces 4 Ajax:隊列inputTextArea不排隊

<h:form> 
    <a4j:queue requestDelay="1000" ignoreDupResponses="true"/> 
    <table> 
     <tr> 
      <td> 
       <h:outputText value="Notes:"/> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <h:inputTextarea value="#{MyActionBean.notes}"> 
        <a4j:ajax event="keyup" listener="#{MyActionBean.updateNotes}"/> 
       </h:inputTextarea> 

筆記按預期更新,但請求之間沒有延遲。我的代碼中是否存在一些錯誤,textAreas不適用於此?任何幫助,將不勝感激。

編輯:只是爲了好的措施,也嘗試了下面的代碼,但它也沒有工作。

<h:panelGrid columns="1" width="100%"> 
    <h:outputText value="Notes:"/> 
    <h:inputTextarea value="#{MyActionBean.notes}"> 
     <a4j:ajax event="keyup" listener="#{MyActionBean.updateNotes}"> 
      <a4j:attachQueue id="notesQueue" requestDelay="1000"/> 
     </a4j:ajax> 
    </h:inputTextArea> 
</h:panelGrid> 

以供參考,該技術的版本: JBoss應用服務器7時,Seam 2.3.0,4.2.2 RichFaces的,JSF 2.1

+0

檢查更新,讓我知道 – Andy

回答

0

對於你的情況,你需要嵌套a4j:attachQueuea4j。嘗試運行下面的代碼,您會注意到您將在15秒後在控制檯上獲得輸出。

<h:head> 
    <title>Facelet Title</title> 
</h:head> 
<h:body> 
    <h:form> 
     <a4j:queue name='Y' requestDelay="3000" ignoreDupResponses="true"/> 
     <h:panelGrid columns="1" width="100%"> 
      <h:outputText value="Notes:"/> 
      <h:inputTextarea value="#{MyActionBean.notes}"> 
       <a4j:ajax event="keyup" listener="#{MyActionBean.updateNotes}"> 
        <a4j:attachQueue requestDelay="3000"/> 
       </a4j:ajax>    
      </h:inputTextarea> 
      <a4j:status> 
       <f:facet name="start"> 
        Please wait 
       </f:facet> 
      </a4j:status> 
     </h:panelGrid> 
    </h:form> 
</h:body> 

您可以使用此link if you need more information

UPDATE

我剝了下來,你發送到最低限度的代碼,我很抱歉地說,它仍然工作在我結束與JBoss的。您的問題可能在其他地方(例如,由於您告訴我「Please Wait」未出現,您的ajax可能因某種原因失敗)。但是,我應該提到我對JBoss的對話範圍並不熟悉,因此我將其更改爲javax.enterprise.context.SessionScoped(但我認爲這不重要,因爲它在請求範圍內仍然有效)。我包含了所有的代碼,所以你可以自己測試它作爲一個單獨的項目。另外,由於我們正在使用隊列,因此我將日誌記錄位置從updateNotes更改爲setReport,以便我可以絕對確定這些字符實際上正在排隊。當我輸入「這是一個測試」時,我看到的唯一輸出是整個字符串,而不是每個字符。

AssessmentCheckListAction.java

import java.io.Serializable; 
import javax.faces.context.FacesContext; 
import javax.inject.Named; 
import javax.enterprise.context.SessionScoped; 

@Named(value="AssessmentChecklistAction") 
@SessionScoped 
public class AssessmentCheckListAction implements Serializable { 

    private static final long serialVersionUID = -4970638494437413924L; 
    private String report; 

    public AssessmentCheckListAction() { 
    } 

    public void updateNotes() { 
     //FacesContext.getCurrentInstance().getExternalContext().log(report); 
     //Logging the setter to make sure everything was queued 
    } 

    public String getReport() { 
     return report; 
    } 

    public void setReport(String report) { 
     FacesContext.getCurrentInstance().getExternalContext().log(report); 
     this.report = report; 
     //left blank 
    } 

的index.xhtml

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html"> 
    <h:head> 
     <title>Facelet Title</title> 
    </h:head> 
    <h:body> 
     <ui:composition xmlns="http://www.w3.org/1999/xhtml" 
         xmlns:ui="http://java.sun.com/jsf/facelets" 
         xmlns:f="http://java.sun.com/jsf/core"      
         xmlns:h="http://java.sun.com/jsf/html"     
         xmlns:a4j="http://richfaces.org/a4j" 
         template="template.xhtml"> 
      <ui:define name="content"> 
       <h:form> 
        <a4j:queue requestDelay="3000" ignoreDupResponses="true"/> 
        <h:panelGrid columns="1" width="100%"> 
         <h:outputText value="Notes:"/> 
         <h:inputTextarea value="#{AssessmentChecklistAction.report}"> 
          <a4j:ajax event="keyup" listener="#{AssessmentChecklistAction.updateNotes}"> 
           <a4j:attachQueue requestDelay="3000"/> 
          </a4j:ajax>    
         </h:inputTextarea> 
         <a4j:status> 
          <f:facet name="start"> 
           Please wait 
          </f:facet> 
         </a4j:status> 
        </h:panelGrid> 
       </h:form> 
      </ui:define> 
     </ui:composition> 
    </h:body> 
</html> 

的template.xhtml

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <h:head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <meta http-equiv="Cache-Control" content="no-store"/> 
     <meta http-equiv="Pragma" content="no-cache"/> 
     <meta http-equiv="Expires" content="0"/>    
    </h:head> 

    <h:body> 
     <ui:insert name="content"/> 
    </h:body> 
</html> 
+0

我試過實現這個,但它仍然發送每個請求到服務器。我在你的例子和我的代碼之間看到的差異是我的包裹在一個中,並且這個應用程序構建在Seam上,所以它使用Name註釋而不是ManagedBean註釋。 (因爲這應該是一個客戶端行爲,我不認爲這是問題) – drandall

+0

對不起,慢回覆。我認爲我們處於同一頁面,通過在表單元素中添加ajax,我們要求客戶端對請求進行排隊,而不是立即發送請求。我添加了但是,當我記錄更新註釋方法時,它仍在發送每個字符。Firebug還顯示每個字符的請求 – drandall

+0

我試着運行您提供的示例代碼,但導致了相同的行爲。這個動作bean正在使用對話範圍。 UI:構圖正在包含在佈局中。基本結構(減去所有額外)佈局中沒有任何表單,它按預期方式提交表單數據,因此沒有嵌套表單。 – drandall