[英]How to implement update handler for Primefaces progressBar?
I have a regular Ajax PF progressBar: 我有一个常规的Ajax PF progressBar:
<p:progressBar value="#{myTask.progress}" labelTemplate="{value}%" ajax="true" widgetVar="progress">
<p:ajax event="complete" oncomplete="progress.cancel();"></p:ajax>
</p:progressBar>
How can I run my JavaScript code whenever progressBar has updated it's value? 每当progressBar更新它的值时,如何运行我的JavaScript代码?
Use the RequestContext
object to execute javascript from the server side. 使用
RequestContext
对象从服务器端执行javascript。 To use this: 要使用它:
Define a method in your backing bean, in which you'll make use of the RequestContext
object 在您的支持bean中定义一个方法,您将在其中使用
RequestContext
对象
public void doJs() { RequestContext ctx = RequestContext.getCurrentInstance(); context.execute("progress.cancel();"); }
Set this method in the listener
attribute of the <p:ajax/>
在
<p:ajax/>
的listener
属性中设置此方法
<p:progressBar value="#{myTask.progress}" labelTemplate="{value}%" ajax="true" widgetVar="progress"> <p:ajax event="complete" listener="#{theBean.doJs}"/> </p:progressBar>
EDIT: To perform the execute after every ajax update, the setup is a little different: 编辑:要在每次ajax更新后执行执行,设置有点不同:
Add the interval
attribute to your progress bar to introduce a better controlled polling mechanism 将
interval
属性添加到进度条以引入更好的受控轮询机制
<p:progressBar value="#{myTask.progress}" labelTemplate="{value}%" ajax="true" widgetVar="progress" interval="3000">
Add an <f:event/>
to hook into the page lifecycle of the component and perform your server-side update from there. 添加
<f:event/>
以挂钩组件的页面生命周期,并从那里执行服务器端更新。 I'm going to recommend the PostValidateEvent
event 我将推荐
PostValidateEvent
事件
<p:progressBar value="#{myTask.progress}" labelTemplate="{value}%" ajax="true" widgetVar="progress" interval="3000"> <f:event type="postValidate" listener="#{theBean.doJs}" /> </p:progressBar>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.