如何以编程方式触发onclick事件 [英] How to programmatically trigger onclick event

查看:53
本文介绍了如何以编程方式触发onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式触发onclick/oncomplete事件?例如

How can I programmatically trigger onclick/oncompleted event? E.g.

<p:commandButton value="Destroy the World" onclick="confirmation.show()" type="button"/>  

<p:confirmDialog message="Are you sure about destroying the world?"  
                 showEffect="bounce" hideEffect="explode"  
                 header="Initiating destroy process" severity="alert" widgetVar="confirmation">
</p:confirmDialog>

我正在尝试从备用bean触发onclick="confirmation.show()". 我正在使用JSF2/Primefaces 2.2.

I'm trying to trigger onclick="confirmation.show()" from a backing bean. I'm using JSF2/Primefaces 2.2.

推荐答案

您应该使用oncomplete属性而不是commandButton的onclick.在页面回发之前,将发生click javascript事件,这可能是由于页面重新加载而导致对话框无法显示.

You should use the oncomplete attribute instead of onclick of the commandButton. The click javascript event occurs before the page posts back, likely causing your dialog not to appear because of the page reloading.

oncomplete="confirmation.show()"将在回发后显示对话框.

oncomplete="confirmation.show()" will display the dialog AFTER the postback.

这篇关于如何以编程方式触发onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆