Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Struts 2.0 and SWF

  1. #1
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default Struts 2.0 and SWF

    Can someone please update me on the status of integration of Struts 2.0 and Spring Web Flow. I would like to use Struts 2.0 as the generic Web layer of my application but would like to have SWF for flow management.

    I came across this pointer from the Struts page, but find that this issue is still "open".

    Any help will be appreciated.

    - Debasish

  2. #2
    Join Date
    Aug 2006
    Location
    Waukesha, WI
    Posts
    41

    Default

    See http://forum.springframework.org/showthread.php?t=25339. I too am hoping to see how they integrate web flow with SAF 2.0. I'm hoping to backport it to webwork in some way, since we're currently in the process of switching over to webwork 2.2.4.

  3. #3
    Join Date
    Aug 2006
    Location
    Waukesha, WI
    Posts
    41

    Default

    I've been working through some of the issues regarding this recently and I think I have at least a partial solution. My goal is to have my Webwork actions be usable both inside and outside the workflow as well as to utilize webwork validation and other features. I wrote an adapter so a Spring Web Flow action can execute a webwork action (complete with interceptors):
    Code:
    /**
     * Allows webwork actions to be executed as Spring Webflow actions.
     */
    public class WebworkFlowAdapter extends AbstractAction
    {
      private static final Log log = LogFactory.getLog(WebworkFlowAdapter.class);
    
      /**
       * Constant for the action's parameters.
       */
      public static final String REQUEST_CONTEXT = "com.opensymphony.xwork.ActionContext.context";
    
      private ActionProxy proxy;
    
      private String actionName;
    
      private String namespace;
    
      private String methodName;
    
      /**
       * @see org.springframework.webflow.action.AbstractAction#doExecute(org.springframework.webflow.RequestContext)
       */
      protected Event doExecute(RequestContext context) throws Exception
      {
        WebworkExternalContext webworkContext = (WebworkExternalContext) context
          .getExternalContext();
        ActionInvocation invocation = webworkContext.getActionInvocation();
    
        // if the finalNamespace wasn't explicitly defined, assume the current one
        if (this.namespace == null)
        {
          this.namespace = invocation.getProxy().getNamespace();
        }
    
        OgnlValueStack stack = ActionContext.getContext().getValueStack();
        String finalNamespace = TextParseUtil.translateVariables(namespace, stack);
        String finalActionName = TextParseUtil
          .translateVariables(actionName, stack);
        String finalMethodName = this.methodName != null ? TextParseUtil
          .translateVariables(this.methodName, stack) : null;
    
        HashMap extraContext = new HashMap();
        extraContext.put(ActionContext.VALUE_STACK, ActionContext.getContext()
          .getValueStack());
        extraContext.put(ActionContext.PARAMETERS, ActionContext.getContext()
          .getParameters());
        extraContext.put(REQUEST_CONTEXT, context);
    
        if (log.isDebugEnabled())
        {
          log.debug("Chaining to action " + finalActionName);
        }
    
        proxy = ActionProxyFactory.getFactory().createActionProxy(finalNamespace,
          finalActionName, extraContext);
        if (null != finalMethodName)
        {
          proxy.setMethod(finalMethodName);
        }
        proxy.setExecuteResult(false);
        proxy.execute();
        String resultCode = proxy.getInvocation().getResultCode();
        return result(resultCode);
      }
    
      /**
       * @return actionName
       */
      public String getActionName()
      {
        return actionName;
      }
    
      /**
       * @param actionName
       */
      public void setActionName(String actionName)
      {
        this.actionName = actionName;
      }
    
      /**
       * @return methodName
       */
      public String getMethodName()
      {
        return methodName;
      }
    
      /**
       * @param methodName
       */
      public void setMethodName(String methodName)
      {
        this.methodName = methodName;
      }
    
      /**
       * @return namespace
       */
      public String getNamespace()
      {
        return namespace;
      }
    
      /**
       * @param namespace
       */
      public void setNamespace(String namespace)
      {
        this.namespace = namespace;
      }
    }
    This code is based heavily on the ActionChainResult. You have to populate the action name, namespace, and (optional) method name as parameters to the action, but I think this will work. (I'm doing some refactoring of the dispatch portion of the WW FlowAction to fit more in line with what we're doing) I won't have time to try this out until Friday, but I'd thought I'd post it if anyone was interested. (Any comments from the Webwork/Struts 2.0 people would be appreciated)

  4. #4
    Join Date
    Aug 2006
    Posts
    143

    Default

    As far as I can tell Spring 2.0 integrates by default with Struts 1.2.9, while Struts 2.0 integrates by default with Spring 1.x.

    There are many reports that Spring 2.0 and Struts 2.0 work fine together, but until Struts 2.0 is released for General Availability (currently in Beta) and it explicitly states that it works with Spring 2.0, I'd question whether it is a safe thing to do with a production system.

  5. #5
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Once Struts 2.0 GA is available, it will be one of the top priorities to get SWF integration done.

    Erwin

  6. #6
    Join Date
    Aug 2006
    Location
    Waukesha, WI
    Posts
    41

    Default

    For those interested in Struts2 integration, please see https://issues.apache.org/struts/browse/WW-1525

    I've uploaded the work I've been doing along with an example app. Very shortly I think it will be intergrated as an official plugin. Feel free to vote for that issue. I'll probably backport the updated code to webwork when it officially becomes available.

  7. #7
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Great stuff!
    Thanks for contributing this!

    Erwin

  8. #8
    Join Date
    Aug 2006
    Location
    Waukesha, WI
    Posts
    41

    Default

    Thanks Erwin!

    I'm really excited about having official support in struts2 for SWF.

  9. #9
    Join Date
    Aug 2006
    Location
    Waukesha, WI
    Posts
    41

    Default

    I took the latest webwork stuff and ported it over to struts2 (based on some of my other work.) Here will be the official project homepage of the struts2webflow integration:
    http://code.google.com/p/struts2webflow/
    (Unless of course it gets included in the struts2 codebase, see https://issues.apache.org/struts/browse/WW-1525 for details)

  10. #10

    Default

    Hi all,

    What is the updates on SWF and Struts2 integration? Since Struts2 is already GA now. Where can I find related info on this?

    Thanks in advance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •