Announcement Announcement Module
Collapse
No announcement yet.
how to retrieve the formObject from flowExecutionKey Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to retrieve the formObject from flowExecutionKey

    /pro/k/_flowExecutionKey

    e.g.
    /pro/k/_c71500A8E-5351-EF44-1978-88BBC9F4D512_k97F4A85C-D7C2-A764-A8EA-7DF7ED463A3A


    is there a possibility to get the formObject by passing only the flowExecutionKey?

    if yes, please guide me.

    thanks in advance..
    Last edited by eros; Dec 2nd, 2009, 10:05 PM. Reason: thread tag as SOLVED

  • #2
    Check this link

    If it is to restore the state of form at navigation time then this is what you will need.

    http://www.ervacon.com/products/swf/intro/index.html

    Hoping that this will help.

    Comment


    • #3
      able to retrieve the formObject via flowExecution

      Thanks Sir sriharshareddyk.

      I created a static method that may able to retrieve the formObject via flowExecution. Will share the class but please give comments or better approach.

      Environment:
      JSP 2.0
      DWR 3.0.M1
      Spring MVC 2.5.2
      SWF 1.0.5
      Tiles 2

      Goal:
      get/set the formObject within the controller(inherit SimpleFormController)

      Code:
      import javax.servlet.ServletContext;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import org.springframework.context.ApplicationContext;
      import org.springframework.webflow.context.ExternalContext;
      import org.springframework.webflow.context.ExternalContextHolder;
      import org.springframework.webflow.context.servlet.ServletExternalContext;
      import org.springframework.webflow.execution.FlowExecution;
      import org.springframework.webflow.execution.repository.FlowExecutionKey;
      import org.springframework.webflow.execution.repository.FlowExecutionRepository;
      import org.springframework.webflow.executor.FlowExecutorImpl;
      import org.springframework.webflow.executor.mvc.FlowController;
      import org.springframework.webflow.executor.support.FlowExecutorArgumentHandler;
      
      /**
       * WebFlowに関連するユーティリティ
       */
      public final class WebFlowUtils {
      
          /**
           * コンストラクタ
           */
          private WebFlowUtils() {
          }
      
          /**
           * WebFlowで管理しているFormObjectを取得する
           * @param request HTTPリクエスト
           * @param response HTTPレスポンス
           * @param applicationContext アプリケーションコンテキスト
           * @param servletContext サーブレットコンテキスト
           * @param formObjectName フォームオブジェクト名
           * @return FormObject
           */
          public static Object getFormObject(HttpServletRequest request, HttpServletResponse response,
                  ApplicationContext applicationContext, ServletContext servletContext,
                  String formObjectName) {
      
              FlowController controller = getFlowController(applicationContext);
      
              FlowExecutorArgumentHandler handler = controller.getArgumentHandler();
      
              ExternalContext externalContext = new ServletExternalContext(servletContext, request,
                      response);
      
              Object object = null;
      
              if (handler.isFlowExecutionKeyPresent(externalContext)) {
                  try {
      
                      ExternalContextHolder.setExternalContext(externalContext);
      
                      FlowExecution flowExecution = getFlowExecution(controller, handler, externalContext);
      
                      object = flowExecution.getActiveSession().getScope().get(formObjectName);
                  } finally {
                      ExternalContextHolder.setExternalContext(null);
                  }
              }
              return object;
          }
      
          /**
           * WebFlowで管理しているFormObjectを取得する
           * @param request HTTPリクエスト
           * @param response HTTPレスポンス3
           * @param applicationContext アプリケーションコンテキスト
           * @param servletContext サーブレットコンテキスト
           * @param formObjectName フォームオブジェクト名
           * @param formObject フォームオブジェクト
           */
          public static void setFormObject(HttpServletRequest request, HttpServletResponse response,
                  ApplicationContext applicationContext, ServletContext servletContext,
                  String formObjectName, Object formObject) {
      
              FlowController controller = getFlowController(applicationContext);
      
              FlowExecutorArgumentHandler handler = controller.getArgumentHandler();
      
              ExternalContext externalContext = new ServletExternalContext(servletContext, request,
                      response);
      
              if (handler.isFlowExecutionKeyPresent(externalContext)) {
                  try {
      
                      ExternalContextHolder.setExternalContext(externalContext);
                      FlowExecution flowExecution = getFlowExecution(controller, handler, externalContext);
      
                      flowExecution.getActiveSession().getScope().put(formObjectName, formObject);
                  } finally {
                      ExternalContextHolder.setExternalContext(null);
                  }
              }
          }
      
          /**
           * FlowExecutionを取得する
           * @param controller フローコントローラ
           * @param handler フローハンドラ
           * @param externalContext 外部コンテキスト
           * @return FlowExecution
           */
          private static FlowExecution getFlowExecution(FlowController controller,
                  FlowExecutorArgumentHandler handler, ExternalContext externalContext) {
              FlowExecutionRepository repository = ((FlowExecutorImpl) controller.getFlowExecutor())
                      .getExecutionRepository();
              FlowExecutionKey flowExecutionKey = repository.parseFlowExecutionKey(handler
                      .extractFlowExecutionKey(externalContext));
              FlowExecution flowExecution = repository.getFlowExecution(flowExecutionKey);
              return flowExecution;
          }
      
          /**
           * フローコントローラを取得する
           * @param applicationContext アプリケーションコントローラ
           * @return フローコントローラ
           */
          private static FlowController getFlowController(ApplicationContext applicationContext) {
              FlowController controller = (FlowController) applicationContext.getBean("flowController");
              
              return controller;
          }
      }

      Comment


      • #4
        updates: upgrade using SWF2.0.9.RELEASE & Spring MVC 2.5.6.SEC02

        I am trying to upgrade the class.

        here's the link:
        obtain the webflow's viewScope data from the MultiActionController

        Comment

        Working...
        X