title: jsf 1.2 getting wrong viewID during restored view phase
body: <p>In my project that I am using the following framework: sun jsf 1.2, spring 2.5, RichFaces ajax4faces, apache orchestra and Facelets.</p>
  
  <p>I developed my own PhaseListener Implementation to trap incoming pages and handling init preproces and prerender events through a Java interface.</p>
  
  <p>When I call a page from a link on an HTML page and afterPhase event is called , I get the correct viewid in the restore_view phase, but when I call another page using a commandButton (using navigation.xml config file) when restore_view phase is invoke the viewid still the same of caller page but not the calling one,  i get the correct viewid of calling page until invoke_application phase is invoke. 
  Therefore the init () method of calling pages do not run when using commnadButton to call it.</p>
  
  <pre><code>here my phaselistener implementation program
  
  package hsbpbnp;
  
  import javax.faces.context.FacesContext;
  import javax.faces.event.PhaseEvent;
  import javax.faces.event.PhaseId;
  import javax.faces.event.PhaseListener;
  
  public class AppPhaseListener implements PhaseListener {
  
          PhaseId phaseid           = null ;
          FacesContext facesContext = null ;
  
  //constructor de la clase
      public AppPhaseListener() {
      }
  
       @Override
       public void beforePhase( PhaseEvent phaseEvent ) {
  
           phaseid = phaseEvent.getPhaseId();
  
           if ( phaseid == PhaseId.RENDER_RESPONSE ) {
  
              facesContext  = phaseEvent.getFacesContext() ;
              String viewId = phaseEvent.getFacesContext().getViewRoot().getViewId() ;
           if( viewId.endsWith( ".xhtml" ) ) {
               String ManagedBeanName = this.getFileName( viewId ) ;
              Object object           = (Object) FacesUtils.getManagedBean( ManagedBeanName ) ;
            if ( object == null ) {
                System.out.println( "no such managed bean " + viewId ) ;
            }else {
                ILifeCycleAware lifeCycleAwareBean = ( ILifeCycleAware ) object ;
                lifeCycleAwareBean.prerender() ;
            }
           }
          }//Fin if RENDER_RESPONSE
  
      }//Fin del metodo beforePhase
  
       @Override
       public void afterPhase( PhaseEvent phaseEvent ) {
           phaseid                = phaseEvent.getPhaseId() ;
           SessionBean1 sb        = ( SessionBean1 )FacesUtils.getManagedBean( "SessionBean1" );
           String ManagedBeanName = " " ;
           if ( phaseid == PhaseId.RESTORE_VIEW ) {
  
  
              facesContext        = phaseEvent.getFacesContext();
              String viewId       = phaseEvent.getFacesContext().getViewRoot().getViewId();
  
           if ( viewId.indexOf( "css" ) != -1 ) return;
  
           if( viewId.endsWith( ".xhtml" ) ) {
              ManagedBeanName = this.getFileName( viewId ) ;
              Object object   = ( Object ) FacesUtils.getManagedBean( ManagedBeanName ) ;
            if ( object == null ) {
                System.out.println( "no such managed bean " + viewId ) ;
            }else {
                ILifeCycleAware lifeCycleAwareBean = ( ILifeCycleAware ) object ;
                lifeCycleAwareBean.init() ;
            }
           }
  
            String ManagedBean = this.getManagedName( viewId );
  
          if( sb.getLastPage().equals( ManagedBean ) ) {
              try {
                  if(FacesUtils.getRequestParameter("from").equals("menu")){
                      sb.setPostback(false);
                      return;
                  }
              } catch (Exception ex){
                 //do nothing 
              }
  
               sb.setPostback( true );
  
           }else {
  
  
  
             String pop = this.firstFive( ManagedBean );
  
             if( pop.equals( "Popup" ) ) {
  
                 return;
  
  
             }else {
  
                 sb.setLastPage( ManagedBean );
                 sb.setPostback( false );
                 sb.setOnLoad1 ( " " );
             }
  
           }
  
         }//Fin if RESTORE_VIEW
  
          if( phaseid == PhaseId.INVOKE_APPLICATION ) {
              facesContext  = phaseEvent.getFacesContext() ;
              String viewId = phaseEvent.getFacesContext().getViewRoot().getViewId() ;
           if( viewId.endsWith( ".xhtml" ) ) {
               ManagedBeanName = this.getFileName( viewId ) ;
              Object object           = ( Object ) FacesUtils.getManagedBean( ManagedBeanName ) ;
            if ( object == null ) {
                System.out.println( "no such managed bean " + viewId ) ;
            }else {
                ILifeCycleAware lifeCycleAwareBean = ( ILifeCycleAware ) object ;
                lifeCycleAwareBean.preprocess() ;
            }
           }
          }//Fin if INVOKE_APPLICATION
  
      }//Fin del metodo afterPhase
  
       @Override
       public PhaseId getPhaseId() {
           return PhaseId.ANY_PHASE ;
       }//Fin del metodo getPhaseId
  
  //Metodo que se encarga de encontrar el nombre del bean de la
  //pagina que esta siendo creada en el ciclo de vida
  
   public String getManagedName( String path ) {
  
          String fileName  = null;
          String separator = "/";
          int pos          = path.lastIndexOf( separator );
          int pos2         = path.lastIndexOf( "." );
          if( pos2 &gt;- 1 )
              fileName     = path.substring( pos + 1, pos2 );
          else
              fileName     = path.substring( pos + 1 );
          return fileName;
  
    }//Fin del metodo getFileName
  
       public String getFileName( String path ) {
  
          String fileName  = null;
          String separator = "/";
          int sep          = path.lastIndexOf( separator );
          int dot          = path.lastIndexOf( "." );
          fileName         = path.substring( sep + 1, dot );
  
      return fileName.substring( 0,1 ).toLowerCase() + fileName.substring( 1 );
  
    }//Fin del metodo getFileName
  
     public String firstFive( String managedBean ) {
  
        String pop = managedBean.substring(0, 5);
  
        return pop;
  
    }//fin del metodo firstFive
  
  }//EOF
  </code></pre>