Icefaces:命令按钮的多个动作监听器
一个命令按钮上是否可以有多个actionListener?
如果没有,有什么办法可以解决这个问题吗?
感谢您的帮助!
Is it possible to have multiple actionListeners on a command button?
If not is there any way around this?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以,您只能添加两个服务器端回调方法:
actionListener
和action
。actionListener
必须指向一个公共方法它返回void
并接受 ActionEvent 作为参数。它通常用于与任何导航逻辑无关的任何任务,并且具有为您提供控件的旧值和新值(=更改的)的优点。这对于复选框等输入控件特别有意义。action
必须指向一个公共方法,该方法返回一个String
而不带任何参数。该方法将执行导航所需的所有操作 - 例如附加验证(如果尚未由某些基本 JSF 验证器处理)。结果必须与faces-config.xml 中的导航规则相匹配。这应该给你足够的可能性来处理服务器逻辑中的多个任务(我认为这是你拥有多个actionListener的原因)。
此外,如果您只需要执行一些客户端任务,则可以利用多个 on* JavaScript 属性。
参考:ICEfaces 自定义组件标签库
No, you can only add two server-side callback methods:
actionListener
andaction
.<ice:commandButton action="#{bean.navigateTo}" actionListener="#{bean.doSomething}"/>
actionListener
has to point to a public method which returnsvoid
and takes an ActionEvent as an argument. It is generally used for any tasks which are not related to any navigation logic and has the advantage, to provide you with the old and new (= changed) value of the control. This makes particular sense in input controls like checkboxes.action
has to point to a public method which returns aString
without taking any arguments. The method will do everything what is needed for navigating - for example additional validation (if it hasn't been handled by some basic JSF validator). The outcome has to match the navigation rules fromfaces-config.xml
.That should give you enough possibilities to handle multiple tasks (which I assume is your reason for having multiple actionListener) within your server logic.
Additionally, if you need to do only some client-side tasks, you can take advantage of several on* JavaScript properties.
Reference: ICEfaces Custom Components Taglib