32.13. <ajax:timer>

AjaxTimer是一个定时器,既可以定时执行客户端脚本,也可以定时执行服务器端动作。通过定时向服务器端发送AJAX请求,向服务器端传递参数。

32.13.1. 构件信息

表 32.29. 构件信息

Component Typeorg.operamasks.faces.component.ajax.AjaxTimer
Component Familyjavax.faces.Command
Component Classorg.operamasks.faces.component.ajax.AjaxTimer
Tag Classorg.operamasks.faces.webapp.ajax.AjaxTimerTag
Renderer Typeorg.operamasks.faces.component.ajax.AjaxTimer
Renderer Class(AJAX)org.operamasks.faces.render.ajax.AjaxTimerRenderer

继承体系

+java.lang.Object

++javax.faces.component.UIComponent

+++javax.faces.component.UIComponentBase

++++javax.faces.component.UICommand

+++++org.operamasks.faces.component.ajax.base.AjaxTimerBase

++++++org.operamasks.faces.component.ajax.AjaxTimer

32.13.2. 属性

表 32.30. 属性

action 定义类 javax.faces.component.UICommand
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
特定Action事件激活时调用的方法
actionListener 定义类 javax.faces.component.UICommand
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
特定ActionEvent事件激活时调用的方法
binding 定义类 javax.faces.component.UIComponentBase
类型 javax.el.ValueExpression(javax.faces.component.UIComponent)
是否必须 延时求值
一个值表达式,用于把该组件链接到一个ManagedBean的某个属性。
delay 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
从启动开始到Timer发出第一次请求之间的时间间隔,单位为秒。默认为0,即启动Timer就立即发送第一次请求
id 定义类 javax.faces.component.UIComponentBase
类型 java.lang.String
是否必须 延时求值
这个组件的组件标识符。这个值在最近的命名容器类型的父组件范围内,必须是唯一的。
immediate 定义类 javax.faces.component.UICommand
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
是否跳过验证
jsvar 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
客户端脚本使用的javascript变量名,引用脚本中OM.ajax.Timer的对象。在客户端脚本中可以调用这个变量的如下方法来控制 Timer:addParameter(name, value)为Timer的服务器端交互添加请求参数;schedule()启动Timer; cancel()取消Timer
onstart 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当timer开始前执行的操作
ontimeout 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当timer及时结束后执行的操作
period 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
Timer两次发送请求之间的时间间隔,单位为秒
rendered 定义类 javax.faces.component.UIComponentBase
类型 boolean(boolean)
是否必须 延时求值
一个标志,指出该组件是否要在任何随后的form提交过程中被渲染或处理。 这个属性的缺省值是true。
sendForm 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否发送表单
start 定义类 org.operamasks.faces.component.ajax.AjaxTimer
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
Timer是否自动启动。true,自动启动;false,需要客户明确调用schedule()方法启动
value 定义类 javax.faces.component.UICommand
类型 java.lang.String
是否必须 延时求值
构件的当前值

32.13.3. 构件API

32.13.4. 例子

<w:form>
 <w:button value="Start Update" onclick="timer.schedule();"/>
 <ajax:timer jsvar="timer" period="5" start="false" action="#{DemoBean.refresh}" />
</w:form>

上例中的ajax:timer客户端构件变量名被设置为updater,构件每5秒钟发起一次ajax请求,start="false"指定了须手工启动该Timer构件,当Timer发起ajax请求时,会调用DemoBean.refresh()方法。

例子中的w:button注册了客户端的onclick事件,当w:button被点击时调用Timer构件的客户端方法schedule(),从而激活Timer构件。