我想在JSF 2.0中为所有请求和响应设计具有单个入口/出口点的应用程序,以便可以通过单个ManagedBean/控制器路由它们.
I want to design my application in JSF 2.0 with single entry/exit point for all the requests and responses so that they can be routed through a single managedBean/controller.
进行这种设计的目的是在一个普通的地方捕获我所有的业务异常,而且对我来说,为每个新请求检查会话的有效性也很容易.
The purpose of having this design is to catch my all business exceptions at common place and also it would be easy for me to check for the validation of session for each new request.
我看到的选项之一是ServletFilter,但是我不确定这是否是JSF 2.0的最佳方法.
One of the option I see is ServletFilter but I am not sure if this would be the best approach with JSF 2.0.
推荐答案
进行此设计的目的是在同一个地方捕获我所有的业务异常
只需实现自定义JSF ExceptionHandler
Just implement a custom JSF ExceptionHandler.
,对我来说,为每个新请求检查会话的有效性也很容易.
这没有任何意义.容器本身已经完成了操作.我相信您是在具体要求检查代表登录用户的会话属性.为此,servlet Filter确实是最明智的方法.某些人可能为此选择使用JSF PhaseListener,但这与JSF请求紧密结合,不会在其他请求上出现.
This makes no sense. The container does it already by itself. I believe that you're concretely asking to check a session attribute representing the logged-in user. For that a servlet Filter is indeed the most sensible approach. Some may opt to use a JSF PhaseListener for that, but this is tight coupled to JSF requests and does not kick in on other requests.
更多推荐
JSF 2.0中的单入口/出口点设计
发布评论