JSF Action Listener - 双重行为
我正在使用 JSF 的 Apache MyFaces 风格,并且我在操作侦听器中遇到了一些奇怪的行为。
当我像这样使用全局 action-listener
时:
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<el-resolver id="msgSrcResolver">com.personal.framework.utils.FacesELResolver</el-resolver>
<message-bundle>resources.errors</message-bundle>
<action-listener>com.personal.framework.listeners.MyActionListener</action-listener>
</application>
JSF 运行良好。 “MyActionListener.processAction(..)”方法通过调用 CommandButton
上列出的 action
方法来工作。不幸的是,由于同一项目中基于 Spring WebFlow 的应用程序中出现了一些冲突,我们无法使用它。
为了解决这个问题,我尝试将操作侦听器直接添加到 CommandButton 中,如下所示:
<h:commandButton id="continue" forceId="true"
image="continue.gif"
action="#{depositBean.postProcess}"
value="Continue">
<f:actionListener type="com.personal.framework.listeners.MyActionListener" > </f:actionListener>
</h:commandButton>
这种使用 ActionListener
的方法无法按预期工作 - 它会调用 <如我所愿,通过 MyActionListener
code>depositBean.postProcess ,但随后在 MyActionListeren 之外再次调用 depositBean.postProcess
。
如何在 CommandButton
中使用 ActionListener
而无需再次调用 Action
(与使用全局ActionListener
)?
注意 - 我们使用 ActionListener
进行验证错误处理,因此所有 Action
方法都必须通过 ActionListener
调用。
I am using the Apache MyFaces flavor of JSFs and I'm experiencing some odd behavior with the Action Listener.
When I use a global action-listener
like this:
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<el-resolver id="msgSrcResolver">com.personal.framework.utils.FacesELResolver</el-resolver>
<message-bundle>resources.errors</message-bundle>
<action-listener>com.personal.framework.listeners.MyActionListener</action-listener>
</application>
the JSFs worked well. The 'MyActionListener.processAction(..)' method worked by calling the action
method listed on the CommandButton
. Unfortunately, we cannot use this due to some conflicts brought up in a Spring WebFlow-based application within the same project.
To fix this, I have tried to add the Action Listener directly to the CommandButton
like so:
<h:commandButton id="continue" forceId="true"
image="continue.gif"
action="#{depositBean.postProcess}"
value="Continue">
<f:actionListener type="com.personal.framework.listeners.MyActionListener" > </f:actionListener>
</h:commandButton>
This method of using the ActionListener
does not work as expected - it will call the depositBean.postProcess
through MyActionListener
as I want, but then depositBean.postProcess
is called again, outside of MyActionListeren.
How can I use the ActionListener
in the CommandButton
without having the Action
called the second time, by itself (in the same way as when using a global ActionListener
)?
Note - we use the ActionListener
for validation error handling so all Action
methods must be called through the ActionListener
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论