private void beforeServletPhase(PhaseEvent event) { if ( event.getPhaseId() == RESTORE_VIEW ) { beforeRestoreView( event.getFacesContext() ); ServletContexts.instance().setRequest((HttpServletRequest) event.getFacesContext().getExternalContext().getRequest()); } handleTransactionsBeforePhase(event); if ( event.getPhaseId() == RENDER_RESPONSE ) { beforeRenderResponse( event.getFacesContext() ); } } /** * Set up the Seam contexts, except for the conversation * context */ protected void beforeRestoreView(FacesContext facesContext) { FacesLifecycle.beginRequest( facesContext.getExternalContext() ); } /** * Restore the page and conversation contexts during a JSF request */ protected void afterRestoreView(FacesContext facesContext) { FacesLifecycle.resumePage(); Map parameters = facesContext.getExternalContext().getRequestParameterMap(); ConversationPropagation.instance().restoreConversationId(parameters); boolean conversationFound = Manager.instance().restoreConversation(); FacesLifecycle.resumeConversation( facesContext.getExternalContext() ); postRestorePage(facesContext, parameters, conversationFound); } private void postRestorePage(FacesContext facesContext, Map parameters, boolean conversationFound) { if ( !Pages.isDebugPage() ) { // Only redirect to no-conversation-view if a login redirect isn’t required if (!conversationFound && !Pages.instance().isLoginRedirectRequired(facesContext)) { Pages.instance().redirectToNoConversationView(); } Manager.instance().handleConversationPropagation(parameters); if ( Init.instance().isJbpmInstalled() && !isExceptionHandlerRedirect() ) { Pageflow.instance().validatePageflow(facesContext); } Pages.instance().postRestore(facesContext); // 이부분에서 바로 pages.xml 설정을 참조하러 가게된다. } } 참고로 FacesLifecycle 에서는 아래와 같이 Request의 시작(초기화)를 시작한다.

   public static void beginRequest(ExternalContext externalContext)
   {
      log.debug( ">>> Begin JSF request for " + getRequestPath(externalContext) );
      Contexts.eventContext.set( new EventContext( externalContext.getRequestMap() ) );
      Contexts.applicationContext.set( new ApplicationContext( externalContext.getApplicationMap() ) );
      Contexts.sessionContext.set( new SessionContext( externalContext.getSessionMap() ) );
      Session session = Session.getInstance();
      if ( session!=null && session.isInvalidDueToNewScheme( Pages.instance().getRequestScheme( FacesContext.getCurrentInstance() ) ) )
      {
         invalidateSession(externalContext);
      }
      Contexts.conversationContext.set(null); //in case endRequest() was never called
      //Events.instance(); //TODO: only for now, until we have a way to do EL outside of JSF!
      saveRequestPath(externalContext);
   }
   public static void resumeConversation(ExternalContext externalContext)
   {
      ServerConversationContext conversationContext = new ServerConversationContext( externalContext.getSessionMap() );
      /*Context conversationContext = Init.instance().isClientSideConversations() ?
            (Context) new ClientConversationContext() :
            (Context) new ServerConversationContext( externalContext.getSessionMap() );*/
      Contexts.conversationContext.set(conversationContext);
      Contexts.businessProcessContext.set( new BusinessProcessContext() );
      conversationContext.unflush();
   }
이후로 Seam Component는 각각의 Context에서 ThreadLocal로 관리된다. seam과 jsf의 연계는 jboss-seam.jar/META-INF/faces-config.xml 에서 정의되어 있다. 아래를 보자면 application-factory태그, application태그, lifecycle태그에서 jsf에서 사용할 핸들러를 설정하고 있다.
<?xml version="1.0"?>
<faces-config version="1.2"
              xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
   <factory>
      <application-factory>org.jboss.seam.jsf.SeamApplicationFactory</application-factory>
   </factory>
   <application>
      <navigation-handler>org.jboss.seam.jsf.SeamNavigationHandler</navigation-handler>
      <view-handler>org.jboss.seam.jsf.SeamViewHandler</view-handler>
      <state-manager>org.jboss.seam.jsf.SeamStateManager</state-manager>
      <el-resolver>org.jboss.seam.el.SeamELResolver</el-resolver>
      <message-bundle>org.jboss.seam.core.SeamResourceBundle</message-bundle>
   </application>
   <lifecycle>
      <phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener>
   </lifecycle>
   <lifecycle>
       <phase-listener>org.jboss.seam.document.DocumentStorePhaseListener</phase-listener>
   </lifecycle>
</faces-config>
]]>

Related Posts