0

In a partner management, when partner number or name is entered, the partner info and photo are shown and input text to introduce partner number or name is hidden.

Then I want to execute a method in my backing bean when ESC or ENTER key are pressed

I catch the keyup event with with following javascript in the view:

<script type="text/javascript">
    $(document).bind('keyup', function(e) {
        debugger;
        if (arguments[0].key == 'Esc') {
            alert("YEAH");
           }
    });
</script>

How can i call my backing bean method???

public void listener() {
    switch (keyCode) {
    case(27):
       // switch boolean attribute in bean to render view hidden panel  
    }
}

I've tryed with remote command or ajax listener:

<p:remoteCommand name="remote" actionListener="#{registerVisitBean.listener}" update="input_table"/>


<f:ajax event="keyup" execute="@this keyCode" listener="#{registerVisitBean.listener}" update="input_table" />
<h:inputHidden id="keyCode" binding="#{keyCode}" value="#{registerVisitBean.keyCode}" />    

Both methods catch the keyup when input text is selected but when i hide it to show partner info, listener stop working.

Any ideas?

Thanks! J

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109

1 Answers1

2
<script type="text/javascript">
    $(document).bind('keyup', function(e) {
        debugger;
        if (arguments[0].key == 'Esc') {
            alert("YEAH");
            // suppose you want to call your listener here
            remote([{name: 'key', value: arguments[0].key}]);
           }
    });
</script>

<p:remoteCommand name="remote" actionListener="#{registerVisitBean.listener}" update="input_table"/>


public void listener() {
   Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
   String keyCode = params.get("key");

   // your code     
}
Multisync
  • 8,657
  • 1
  • 16
  • 20