对于您的情况,您需要嵌套a4j:attachQueue
在a4j
. 尝试运行下面的代码,您会注意到 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>
如果您需要更多信息,可以使用此链接
更新
我将您发送的代码精简到最低限度,我很遗憾地说它仍在为我的 JBoss 工作。您的问题可能出在其他地方(例如,您的 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
}
索引.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>
模板.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>