1

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>

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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
blukit
  • 113
  • 2
  • 5
  • 12

2 Answers2

1

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.

maple_shaft
  • 10,435
  • 6
  • 46
  • 74
0

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();
Rok Kralj
  • 46,826
  • 10
  • 71
  • 80