public FacesBackingBean getFacesBackingBeanForRequest ( RequestContext requestContext ) { HttpServletRequest request = requestContext . getHttpRequest ( ) ; String uri = InternalUtils . getDecodedServletPath ( request ) ; assert uri . charAt ( 0 ) == ' ' : uri ; String backingClassName = FileUtils . stripFileExtension ( uri . substring ( 1 ) . replace ( ' ' , ' ' ) ) ; FacesBackingBean currentBean = InternalUtils . getFacesBackingBean ( request , getServletContext ( ) ) ; // // If there is no current backing bean, or if the current one doesn't match the desired classname, create one. // if ( currentBean == null || ! currentBean . getClass ( ) . getName ( ) . equals ( backingClassName ) ) { FacesBackingBean bean = null ; if ( FileUtils . uriEndsWith ( uri , FACES_EXTENSION ) || FileUtils . uriEndsWith ( uri , JSF_EXTENSION ) ) { bean = loadFacesBackingBean ( requestContext , backingClassName ) ; // // If we didn't create (or failed to create) a backing bean, and if this is a JSF request, then create // a default one. This ensures that there will be a place for things like page inputs, that get stored // in the backing bean across postbacks to the same JSF. // if ( bean == null ) bean = new DefaultFacesBackingBean ( ) ; // // If we created a backing bean, invoke its create callback, and tell it to store itself in the session. // if ( bean != null ) { HttpServletResponse response = requestContext . getHttpResponse ( ) ; try { bean . create ( request , response , getServletContext ( ) ) ; } catch ( Exception e ) { _log . error ( "Error while creating backing bean instance of " + backingClassName , e ) ; } bean . persistInSession ( request , response ) ; return bean ; } } // // We didn't create a backing bean. If there's one in the session (an inappropriate one), remove it. // InternalUtils . removeCurrentFacesBackingBean ( request , getServletContext ( ) ) ; } else if ( currentBean != null ) { if ( _log . isDebugEnabled ( ) ) { _log . debug ( "Using existing backing bean instance " + currentBean + " for request " + request . getRequestURI ( ) ) ; } currentBean . reinitialize ( request , requestContext . getHttpResponse ( ) , getServletContext ( ) ) ; } return currentBean ; }
Get the backing bean associated with the JavaServer Faces page for a request .