I'm new to all these technologies and depend on Google to find me solutions but I couldn't find anything that helped me to do this with Sun Reference Implementation of JSF. I found one that described how to do it in IBM implementation of JSF which obviously didn't work on Sun RI. The problem is you just can't redirect to a JSP in the doView method if you are using JSF. I tried to do it by overriding the doView method in FacesPortlet.
Then I found this article on JSF Central which described how to redirect a user to a login page if the user is not logged in and that's exactly what I wanted. All I had to do was
- Write a PhaseListener and in the beforePhase method do my database check and set the view ID to my start page view id if the value had changed.
- Change the getPhaseId method to return PhaseId.RENDER_RESPONSE which makes the PhaseListner fire every time a page is rendered. The PhaseId.RESTORE_VIEW event is not fired every time a portlet is rendered.
- Configure the PhaseListener in faces-config.xml
And the faces-config.xml
<!-- rest of the faces-config -->