问题
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.
One of the option I see is ServletFilter but I am not sure if this would be the best approach with JSF 2.0.
回答1:
The purpose of having this design is to catch my all business exceptions at common place
Just implement a custom JSF ExceptionHandler.
and also it would be easy for me to check for the validation of session for each new request.
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.
来源:https://stackoverflow.com/questions/13892473/single-entry-exit-point-design-in-jsf-2-0