1/25/2011

ICEFaces request scope (and the consequences)

ICEFaces offers its own interpretation of the JSF request scope : the extended request scope.


This request scope lasts longer than the original request scope: It will continue to live when you are using partialSubmit controls and it will continue to live when you are using non-redirect navigation rules.


This means for example, that when you are navigating back and forth within two pages your beans won´t be recreated which then means that you can´t put code into the constructor of your beans because it will only be executed once.


But sometimes you have the need for backing beans to be recreated every time a page is requested. To avoid having to deal with JQuery you have two possibilities:


What to do when you have a simple ICEFaces application

If you have a simple ICEFaces application that is NOT running in a portlet environment, you can just add a redirect to your faces-config navigation rule:


<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>edit</from-outcome>
<to-view-id>/pages/editPage.iface</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>


This redirects to the specified pages, thus leaving the extended portlet request and therefore recreating your managed beans. 


What to do in a Portal Environment (Liferay)


You can´t use the faces-config redirect mechanism in a portklet environment because you don´t want to see the ICEFaces page but instead the portlet page with the ICEFaces - Portlet in it. To redirect to the portlet page you are just visiting, use the following snippet:



String portalURL = themeDisplay.getPortalURL();
String urlCurrent = themeDisplay.getURLCurrent();
FacesContext.getCurrentInstance().getExternalContext()
.redirect(portalURL + urlCurrent);




This will redirect to the current Page (which is the Page your portlet is running on) using a standard JSF mechanism. 



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.