2

次のように追加できることを理解actionListenercommandButtonています。

<h:commandButton value="ClickMe">
    <f:actionListener type="com.mycompany.MyActionListener" />
</h:commandButton>

しかし、どうすれactionListenerば文書に (本文だけでなく文書全体) を追加できますか? 私がこれを行っている理由は、ユーザーがページ内の任意の場所をクリックしたときに、メソッドをトリガーしたいからです。

4

1 に答える 1

0

クリック検出に jquery を使用できます。

$(document).click(function(e) { 
    // control if it is the left button
    if (e.button == 0) {
        functionToTrigger();
   }
});

...h:commandButtonメソッドを同期的にトリガーしたい場合、または(できれば)a4j:jsFunction非同期的にトリガーしたい場合は非表示:

<a4j:jsFunction name="functionToTrigger"
    execute="@this"
    actionListener="#{myManagedBean.myAction}"/>
于 2014-07-17T13:19:47.883 に答える