2

I understand we can add actionListener to commandButton as:

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

But how can I add an actionListener to document (entire document, not just body)? The reason I am doing this is when user clicks on anywhere in the page, I want to trigger a method.

SwiftMango
  • 15,092
  • 13
  • 71
  • 136

1 Answers1

0

you can use jquery for click detection:

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

... and a hidden h:commandButton if you want to trigger the method synchronously, or (preferably) a4j:jsFunction to trigger it asynchronously:

<a4j:jsFunction name="functionToTrigger"
    execute="@this"
    actionListener="#{myManagedBean.myAction}"/>
tt_emrah
  • 1,043
  • 1
  • 8
  • 19