JSF getter methods called BEFORE beforePhase fires
        Posted  
        
            by Bill Leeper
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Bill Leeper
        
        
        
        Published on 2010-04-22T15:48:26Z
        Indexed on 
            2010/04/23
            17:53 UTC
        
        
        Read the original article
        Hit count: 231
        
I got a recommendation to put all data lookups in the beforePhase for a given page, however, now that I am doing some deeper analysis it appears that some getter methods are being called before the beforePhase is fired.
It became very obvious when I added support for a url parameter and I was getting NPEs on objects that are initialized in the beforePhase call.
Any thoughts? Something I have set wrong.
I have this in my JSP page:
<f:view beforePhase="#{someController.beforePhaseSummary}">
That is only the 5th line in the JSP file and is right after the taglibs.
Here is the code that is in the beforePhaseSummary method:
public void beforePhaseSummary(PhaseEvent event) {
    logger.debug("Fired Before Phase Summary: " + event.getPhaseId());
    if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        if (request.getParameter("application_id") != null) {
            loadApplication(Long.parseLong(request.getParameter("application_id")));
        }
        /* Do data fetches here */
    } 
}
The logging output above indicates that an event is fired. The servlet request is used to capture the url parameters. The data fetches gather data. However, the logging output is below:
2010-04-23 13:44:46,968 [http-8080-4] DEBUG ...SomeController 61 - Get Permit
2010-04-23 13:44:46,968 [http-8080-4] DEBUG ...SomeController 107 - Getting UnsubmittedCount
2010-04-23 13:44:46,984 [http-8080-4] DEBUG ...SomeController 61 - Get Permit
2010-04-23 13:44:47,031 [http-8080-4] DEBUG ...SomeController 133 - Fired Before Phase Summary: RENDER_RESPONSE(6)
The logs indicate 2 calls to the getPermit method and one to getUnsubmittedCount before the beforePhase is fired.
© Stack Overflow or respective owner