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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.