1

jsf 2 プロジェクトでは、ID が「displayDialog」の commandButton が非表示になっています。JavaScript関数によってトリガーされます:

 document.getElementById('displayDialog').click();

問題は、「onclick」ではなく「oncomplete」の段階でクリックアクションを実行する必要があるということです(@BalusC here で説明されている理由により)。

私はやろうとしました:

    <p:commandButton style="display: none" id="displayDialog" type="button" onclick="" oncomplete="cd.show();"/>

また

    <p:commandButton style="display: none" id="displayDialog" type="button" onclick="return false;" oncomplete="cd.show();"/>

ただし、どちらの場合も cd.show() は実行されません。これはどのように行うべきですか?

(onclick 属性にダミーのアクションを追加する必要がありますか? その場合、どのアクションを追加しますか?)

4

1 に答える 1

2

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.

于 2012-10-28T14:57:21.043 に答える