Kishor Prakash
Kishor Prakash

Reputation: 8171

Action and ActionListener are not invoked for p:remoteCommand

I'm using p:remoteCommand,its working fine for update and process except its not invoking either action method nor actionListener

Xhtml Code

<h:form id="mainForm">
   <h:outputLabel id="tempAge" value="#{remoteBean.tempAge}"/>

   <h:inputText id="age" value="#{remoteBean.age}" onkeypress="callRem()">
      <f:validateLongRange minimum="18"/>
   </h:inputText>

   <script type="text/javascript">
     var timex=0;
     function callRem(){
    clearTimeout(timex);
    timex = setTimeout("remote()",2000);
      }
   </script>

   <p:remoteCommand     name="remote" 
            process="age" 
            update="tempAge"
            action="#{remoteBean.act}" 
            actionListener="#{remoteBean.listen}">
   </p:remoteCommand>

</h:form>

Managed Bean Code

@ManagedBean
public class RemoteBean {
    private int age=18;
    private int tempAge=20;
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
        System.out.println("Setting age :"+age);
    }
    public int getTempAge() {
        return tempAge;
    }
    public void setTempAge(int tempAge) {
        this.tempAge = tempAge;
    }

    public void act(){
        System.out.println("in action()");
        tempAge+=age+2;
    }

     public void listen(ActionEvent event) {
         System.out.println("in Action Listener");
         tempAge+=age+2;
     }

}

I can't figure out where I'm doing wrong, may be its the Javascript code i've written.
If anyone faces and solved same issue please help.

Using: Primefaces 3.5

Upvotes: 2

Views: 8318

Answers (1)

Darka
Darka

Reputation: 2768

I tried yours example and found problem. Seemse when you processing only age (process="age"), it executes only age input and ignores remoteCommand actionListener and action. So you can change it to:

process="@form" 

or

process="@this age" 

worked both for me.

ps. I used View scope here.

Upvotes: 12

Related Questions