How to programmatically trigger onclick event
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"
开发者_Go百科 header="Initiating destroy process" severity="alert" widgetVar="confirmation">
</p:confirmDialog>
I'm trying to trigger onclick="confirmation.show()"
from a backing bean.
I'm using JSF2/Primefaces 2.2.
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()"
will display the dialog AFTER the postback.
Since the click contains only one call, you can call the code directly:
confirmation.show();
But if you want to do it your way and if you use jQuery, you can simply do:
$('p[type=button]').click();
精彩评论