【发布时间】:2011-12-24 09:00:25
【问题描述】:
我有以下按钮:
<h:commandButton
disabled="#{mybean.searching}"
binding="#{mybean.searchButton}"
actionListener="#{mybean.searchForLicenses}"
value="Search" />
当我调试时,我看到 actionListener 先被调用了两次,然后是 3 次,然后单击了 4 次,依此类推。
似乎在每次重新加载时,actionListener 都会再注册一次。
我正在使用 Mojarra 2.1.3(也尝试过 2.0.6)和带有 IceFaces 的 Tomcat 7。
绑定是这样完成的:
private javax.faces.component.UICommand searchButton;
public void setSearchButton(UICommand searchButton) {
this.searchButton = searchButton;
}
public UICommand getSearchButton() {
return searchButton;
}
【问题讨论】:
-
绑定是怎么做的?你能发布 get/setSearchButton 的所有相关代码吗?
-
删除绑定后问题就消失了。 @mrembisz:我添加了绑定代码(抱歉,它没有格式化,因为我在页面上收到阻止编辑器加载的病毒警告)。
-
当您指定绑定时,如果持有 bean 仍在范围内,您的组件将被重用。单个组件上可以有多个 actionListener,因此每个请求都会向您的命令注册一个新的侦听器。