如何实现在生命周期结束时运行的 PhaseListener?
如何实现在 JSF 生命周期结束时运行的 PhaseListener
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何实现在 JSF 生命周期结束时运行的 PhaseListener
?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
您需要实现
PhaseListener
接口并挂钩 <代码> href="http://docs.oracle.com/javaee/6/api/javax/faces/event/PhaseId.html#RENDER_RESPONSE" rel="noreferrer">PhaseId_RENDER_RESPONSE
。渲染响应是 JSF 生命周期的最后一个阶段。要使其运行,请在faces-config.xml中按如下方式注册:
更新上述阶段侦听器确实是应用程序范围内的。要为特定视图设置阶段侦听器,请使用 beforePhase 和/或
afterPhase
属性/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/view.html" rel="noreferrer">
。例如,
更多
的 JSF 2.0 方式是使用
:与
You need to implement the
PhaseListener
interface and hook onbeforePhase()
of thePhaseId_RENDER_RESPONSE
. The render response is the last phase of the JSF lifecycle.To get it to run, register it as follows in
faces-config.xml
:Update the above phase listener is indeed applicaiton-wide. To have a phase listener for a specific view, use the
beforePhase
and/orafterPhase
attributes of the<f:view>
.E.g.
with
A more JSF 2.0 way is by the way using the
<f:event type="preRenderView">
:with
在 jsf 2 中,您可以使用
为某些facelet 挂钩
。MyPhaseListener
MyPhaseListener
应该实现PhaseListener
并覆盖afterPhase
- 代码在阶段结束后运行beforePhase
- 代码在阶段启动之前运行getPhaseId
-PhaseId
枚举,指定要调用侦听器的阶段名称(
PhaseId.RENDER_RESPONSE
作为生命周期的最后阶段)In
jsf 2
you can use<f:phaseListener type="my.MyPhaseListener">
to hookMyPhaseListener
for somefacelet
.MyPhaseListener
should implementPhaseListener
and overrideafterPhase
- with code to be run after end of phasebeforePhase
- with code to be run before phase startedgetPhaseId
-PhaseId
enum specifying name of phase for which the listener to be invoked(
PhaseId.RENDER_RESPONSE
as last phase of lifecycle)