0

Is it possible to trigger a click on commandButton on oncomplete attribute of another commandButton?

Like this :

<p:commandButton value="save" action="#{myBean.save} oncomplete="trigger button2" />
<p:commandButton value="print" ajax="false" action="#{myBean.print}" widgetVar="button2" />

Second button is with attribute ajax="false".

2 Answers 2

6

Well, the answer was in my question -.-

<p:commandButton value="save" action="#{myBean.save}" oncomplete="$('#print').click();" />
<p:commandButton value="print" id="print" ajax="false" action="#{myBean.print}" />

Save the form, then trigger button2 click.

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

Comments

5

You can use p:remoteCommand as :

<p:remoteCommand name="callButton2" action="#{myBean.print}" />

Then in your button-1

<p:commandButton value="save" action="#{myBean.save} 
 oncomplete="callButton2()" />

Now if you press Save, on complete It'll call print method.

Remember you should have p:remoteCommand inside the form.

4 Comments

I think p:remoteCommand does an ajax call right? I need a non-ajax post in my second commandButton :/ (exporting a pdf)
You didn't mention in your question. Try to give as much as information as possible.
Edited my question, second button was with attribute ajax="false"
Thx Makky, that's a great trick to get a post callback function server-side in order to let primefaces completes its process and only applies rendering finishes afterwards. You've just saved my day!

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.