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
<faces-config>
<lifecycle>
<phase-listener>com.test.DBPhaseListener</phase-listener>
</lifecycle>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>main</from-outcome>
<to-view-id>/WEB-INF/jsp/index.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<!-- rest of the faces-config -->
</faces-config>
1 comment:
Create \html\Hello.jsp under the Web Content folder. Add only one line in this file, saying "Help.jsp - HelloWorld Portlet in Help mode."
Change HelloWorld.java to add the doHelp() method, like this:
protected void doHelp(RenderRequest request,
RenderResponse response)
throws PortletException, IOException {
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher
("/html/helloworld.jsp");
dispatcher.include(request, response);
}
Post a Comment