多次调用ActionListener(错误?)-Mojarra 2.1.3 [英] ActionListener is called multiple times (Bug?) - Mojarra 2.1.3

查看:73
本文介绍了多次调用ActionListener(错误?)-Mojarra 2.1.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下按钮:

   <h:commandButton 
     disabled="#{mybean.searching}"
     binding="#{mybean.searchButton}"
     actionListener="#{mybean.searchForLicenses}"
     value="Search" />

调试时,我看到actionListener首先被调用两次,然后被调用三次,然后单击四次,依此类推.

When I debug I see that the actionListener is called twice first, then three times, next click four times and so on.

似乎在每次重新加载时,actionListener都会再注册一次.

It seems like on every reload the actionListener is registered one more time.

我正在将Mojarra 2.1.3(也尝试2.0.6)和Tomcat 7与IceFaces一起使用.

I'm using Mojarra 2.1.3 (also tried 2.0.6) and Tomcat 7 with IceFaces.

绑定是这样完成的:

private javax.faces.component.UICommand searchButton;

public void setSearchButton(UICommand searchButton) {
  this.searchButton = searchButton;
}

public UICommand getSearchButton() {
  return searchButton;
}

推荐答案

如果您已将组件绑定到会话或应用程序范围的bean而不是请求范围的bean,则可能会发生这种情况.这简直是​​一个糟糕的设计.完全相同的组件将在多个请求/视图之间重用.您需要将bean放在请求范围内,或者完全摆脱组件绑定.

That can happen if you've bound the component to a session or application scoped bean instead of a request scoped bean. This is simply a bad design. The very same component would be reused among multiple requests/views. You need to put the bean in the request scope, or to get rid of the component binding altogether.

请注意,将组件直接绑定到Bean通常是代码中某些地方设计不良的标志.您认为这是解决方案的功能,功能要求和/或问题是什么?如果您对此进行详细说明,我们也许可以提出正确的方法.

Note that binding the component directly to a bean is often a sign of poor design somewhere in the code. What is it, the functional requirement and/or problem for which you thought that this is the solution? If you elaborate on that, we may be able to propose the right approach.

还请注意,单独使用动作侦听器也是一种设计气味.我希望"searchForLicenses"是一种正常的操作方法.另请参见 action与actionListener之间的差异.

Also note that using an action listener alone is also a design smell. I'd expect "searchForLicenses" to be a normal action method. See also Differences between action and actionListener.

这篇关于多次调用ActionListener(错误?)-Mojarra 2.1.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆