如何在每个页面请求上调用bean方法 [英] How to call bean method on every page request

查看:176
本文介绍了如何在每个页面请求上调用bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作中,我们开发了一个JSF 2应用程序.而且我需要使用一种必须在每个页面请求上执行的方法来创建一个侦听器bean.如何完成这项任务?

In my work we develop an JSF 2 application. And I need to create a listener bean with one method which have to be executed on every page request. How to accomplish this task?

推荐答案

我解决了.最初,我尝试使用过滤器,但这不是因为在请求开始时调用了过滤器,但是那时FacesContext尚未初始化,我需要这样做,因为我必须检索所请求的url.因此,在那之后,我尝试使用相位监听器,并且可以正常工作!在beforePhase()方法中,我监听PhaseId.RENDER_RESPONSE.谢谢大家的指导.

I solved it. At first I tried with filter but it didn't because the filter is called at begining of the request, but at that time FacesContext is not initialised and I needed because I have to retrieve the requested url. So after that I tried with phase listener and it works! In beforePhase() method I listen for PhaseId.RENDER_RESPONSE. Thank you all for guidance.

这篇关于如何在每个页面请求上调用bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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