同时执行 PrimeFaces p:poll
Execute PrimeFaces p:poll concurrently
这是代码的第一部分:(目标 = 每 2 秒更新一个组件)
<p:poll id="pollid"
async="true"
immediate="true"
interval="2"
update="log"
widgetVar="poll"/>
这是第二部分:(description = long-运行 将不断修改组件 "log" 的函数
<p:commandButton id="running"
value="#{Nbt.execution}"
actionListener="#{Nbt.launchModule}"
async="true"
ajax="true"
immediate="true"
update="log">
</p:commandButton>
详细信息:"log" 是 <p:inputTextarea>
的 ID
理论上,也许它应该有效,但我的 <p:inputTextarea>
没有逐渐填充。
等待"long-running"方法结束。
问题是当您 update
<p:inputTextarea>
时,您还 提交 该文本区域的当前内容,它是空白的( JSF 生命周期应用于该组件)。将您的 <p:inputTextarea>
更改为 <h:outputText>
,它应该可以工作。
为了说明问题,请看这个 Facelets 页面:
<h:form>
<p:inputTextarea id="txt_count" value="#{backingBean.text}"/>
<p:poll interval="3" update="txt_count" />
<p:commandButton value="Long running" async="true" action="#{backingBean.longRunning}"/>
</h:form>
还有这个辅助 bean:
@ManagedBean
@SessionScoped
public class BackingBean {
private String text = "";
public String getText() {
System.out.println("GET: " + text);
return text;
}
public void setText(String text) {
System.out.println("SET: " + text);
this.text = text;
}
public void longRunning() throws InterruptedException {
text = "";
for (int i = 0; i < 20; i++) {
text += "a";
Thread.sleep(1000);
}
}
}
运行 它并单击按钮。服务器日志将显示如下内容:
Info: GET:
Info: GET:
Info: SET:
Info: GET: a
Info: SET:
Info: GET:
Info: GET: aaa
Info: SET:
Info: GET:
Info: GET: aaa
Info: SET:
Info: GET:
Info: GET: aaa
Info: SET:
Info: GET:
如果您使用浏览器的开发人员工具,您也可以在 POST headers 中看到它。
将 <p:inputTextarea>
替换为 <h:outputText>
,它会打印出越来越长的字符串。
这是代码的第一部分:(目标 = 每 2 秒更新一个组件)
<p:poll id="pollid"
async="true"
immediate="true"
interval="2"
update="log"
widgetVar="poll"/>
这是第二部分:(description = long-运行 将不断修改组件 "log" 的函数
<p:commandButton id="running"
value="#{Nbt.execution}"
actionListener="#{Nbt.launchModule}"
async="true"
ajax="true"
immediate="true"
update="log">
</p:commandButton>
详细信息:"log" 是 <p:inputTextarea>
理论上,也许它应该有效,但我的 <p:inputTextarea>
没有逐渐填充。
等待"long-running"方法结束。
问题是当您 update
<p:inputTextarea>
时,您还 提交 该文本区域的当前内容,它是空白的( JSF 生命周期应用于该组件)。将您的 <p:inputTextarea>
更改为 <h:outputText>
,它应该可以工作。
为了说明问题,请看这个 Facelets 页面:
<h:form>
<p:inputTextarea id="txt_count" value="#{backingBean.text}"/>
<p:poll interval="3" update="txt_count" />
<p:commandButton value="Long running" async="true" action="#{backingBean.longRunning}"/>
</h:form>
还有这个辅助 bean:
@ManagedBean
@SessionScoped
public class BackingBean {
private String text = "";
public String getText() {
System.out.println("GET: " + text);
return text;
}
public void setText(String text) {
System.out.println("SET: " + text);
this.text = text;
}
public void longRunning() throws InterruptedException {
text = "";
for (int i = 0; i < 20; i++) {
text += "a";
Thread.sleep(1000);
}
}
}
运行 它并单击按钮。服务器日志将显示如下内容:
Info: GET:
Info: GET:
Info: SET:
Info: GET: a
Info: SET:
Info: GET:
Info: GET: aaa
Info: SET:
Info: GET:
Info: GET: aaa
Info: SET:
Info: GET:
Info: GET: aaa
Info: SET:
Info: GET:
如果您使用浏览器的开发人员工具,您也可以在 POST headers 中看到它。
将 <p:inputTextarea>
替换为 <h:outputText>
,它会打印出越来越长的字符串。