【问题标题】:Action and ActionListener are not invoked for p:remoteCommand不为 p:remoteCommand 调用 Action 和 ActionListener
【发布时间】:2013-09-06 06:40:49
【问题描述】:

我正在使用p:remoteCommand,它对updateprocess 工作正常,除了它既不调用action 方法也不调用actionListener

Xhtml 代码

<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>

托管 Bean 代码

@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;
     }

}

我不知道我在哪里做错了,可能是我编写的 Javascript 代码。
如果有人遇到并解决了同样的问题,请帮忙。

使用:Primefaces 3.5

【问题讨论】:

    标签: javascript jsf primefaces


    【解决方案1】:

    我尝试了您的示例并发现了问题。 似乎当您只处理年龄(process =“age”)时,它只执行年龄输入并忽略 remoteCommand actionListener 和 action。 所以你可以把它改成:

    process="@form" 
    

    process="@this age" 
    

    两者都为我工作。

    ps。我在这里使用了 View 范围。

    【讨论】:

    • 感谢 Darka 这解决了我的问题。我将@this 包含在要处理的元素列表中。
    猜你喜欢
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 2012-07-29
    • 2010-11-10
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多