Reputation: 10798
In a jsf 2 project, a commandButton with id "displayDialog" is hidden. It gets triggered by a javascript function:
document.getElementById('displayDialog').click();
The thing is, I need the click action to be performed at the stage of "oncomplete", not "onclick" (for a reason explained by @BalusC here).
I tried to do:
<p:commandButton style="display: none" id="displayDialog" type="button" onclick="" oncomplete="cd.show();"/>
or
<p:commandButton style="display: none" id="displayDialog" type="button" onclick="return false;" oncomplete="cd.show();"/>
but in both cases cd.show() is not actioned. How should this be done?
(Should I just add a dummy action in the onclick attribute? If so which one?)
Upvotes: 1
Views: 26077
Reputation: 995
The oncomplete
method is invoked after an ajax request, and when you say that type="button"
, no ajax request will be made.
That said, just remove the type="button"
parameter and you don't have to implement onclick
at all.
<p:commandButton style="display: none"
id="displayDialog"
oncomplete="cd.show();"/>
But, do you really need the button to be called from a JavaScript function? If there is another component making the first request, can't you just implement the oncomplete
method of that component?
In your code, the p:commandButton
has no action at all, then why do you need to wait for the action to be completed? Are you submitting a form or something?
Maybe if you explain exactly what you want to do, we can think of a better way to do it.
Upvotes: 2