I want to know if there is an interceptor in JSF (like we use in Spring), and how to do we implement it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could implement a
PhaseListenerfor this. You could program them to listen on a specific JSF phase which you specify in the overriddengetPhaseId()method. You can intercept on the before and after phase events bybeforePhase()andafterPhase()methods.The below example listens on the render response phase:
To get it to run, you need to register it as a
<phase-listener>in the<life-cycle>section of thefaces-config.xmlfile. You can have multiple<phase-listener>s.You can specify
PhaseId.ANY_PHASEingetPhaseId()to let the phase listener run on every single JSF phase (note that not necessarily all of them will always be executed, that depends on the request type). You can if necessary get the current phase ID in the before and after phase methods byPhaseEvent#getPhaseId().Alternatively, a
Filtershould work equally good if you want a more global hook (and thus you’re not exactly interested in JSF requests/responses and you do not need anything from theFacesContext).