Thursday, October 3, 2013

When to use facesContext Redirect vs context Redirect + What I found in the bottom of my closet

I haven't had much useful to say lately.  I am just plugging along in my very large Purchase Order system project.   I think I have reached the point where I just want it done.  I know from experience that this means that I need to be extra careful to not cut corners and let my quality of work slip.  Today I did discover something worthy of sharing.

I discovered the difference between these two lines of code:

facesContext.getExternalContext().redirect("home.xsp");

context.redirectToPage("home.xsp");

On the surface they appear to do the same thing, but here is the difference.   The first one will continue evaluating the rest of the code before redirecting.  If that code happens to encounter a second redirect you will get an error that in Chrome looks like the following.


The second line will redirect the page immediately and you won't get the error.   I imagine that this has something to do with the JSF lifecycle if I had to guess.   If anyone wants to further elaborate then please comment.

Speaking of the JSF lifecycle, I think I am now ready to rewatch and this time understand the Xpages Masterclass.   I have watched at least the first two videos before, but honestly I wasn't ready for them.   I watched them back when they came out in the Spring and I really tried to understand, but mostly my eyes glazed over.  (Let me add my not understanding the material in no way reflects the quality of the presentation).  In my opinion, unless you are a genius this course won't help you much until you have gained some heavy real world xpages experience.  I will be diving into them soon.

Look what I found in my closet, who remembers these?

Lastly, I would like to join chorus in thanking Bruce Elgort.  I don't think I have ever met him personally but I have most definitely benefited from his efforts in the Notes community.   Thank you Bruce!