I have created a phase listener for my portlet. It’s working, but it has a weird first behavior.
When a view or a page loads for the very first time, according to JSF theory, it should go inside the RESTORE_VIEW phase first and then to the RENDER_RESPONSE phase. I tested this in a JSF application and it confirms this statement. When I use my phase listener class in a Webmethod portlet, the first time it loads, it only goes into the RENDER_RESPONSE phase without going inside the RESTORE_VIEW phase.
I really don’t know why it does not go inside the RESTORE_VIEW phase the first time the page is being loaded. Any explications? clues or work around?
In jsf 1.1 (which is what mws 7 uses), there are three lifecycle scenarios: non-faces request generates faces response, faces request generates faces response, and faces request generates non-faces response. The first scenario is what happens when you view a page for the first time. In this case, the lifecycle processing invokes only the final stage of the faces lifecycle, RENDER_RESPONSE.
If you want to invoke some code at the very earliest point in the faces lifecycle, the best way to do it is have your phase listener listen for both RESTORE_VIEW and RENDER_RESPONSE beforePhase events, setting a flag in your RESTORE_VIEW processing so that when the RENDER_RESPONSE phase comes around, you’ll know whether or not you already did the processing.