struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Néstor Boscán <nestor.bos...@tcsapp.com.ve>
Subject Struts 2 and DWR
Date Fri, 24 Aug 2007 14:59:19 GMT
Hi 
 
I created a code based on the WebWork code that can invoke a Struts 2 Action
from DWR. You can invoke it just like the WebWork version and you can use
DWRActionUtil.js. It does not do everything that the WebWorks code does, it
invokes de Action method and returns the Action object. Hope somebody finds
it useful.
 
public class DWRAction
{
  private static final Logger log = Logger.getLogger (DWRAction.class);
    
  public static Object execute (ActionDefinition actionDefinition, Map
params, HttpServletRequest request, HttpServletResponse response,
ServletContext servletContext) throws Exception {
    ActionMapping             mapping;
    Dispatcher                dispatcher;
    Map                       context;
    ActionProxy               proxy;
 
    try
    {
      dispatcher = Dispatcher.getInstance ();
      mapping    = new ActionMapping (actionDefinition.getAction(),
actionDefinition.getNamespace(), actionDefinition.getMethod(), params);
      context    = dispatcher.createContextMap (request, response, mapping,
servletContext);
 
      proxy      = ((ActionProxyFactory) dispatcher.getContainer
().getInstance (ActionProxyFactory.class)).createActionProxy
(actionDefinition.getNamespace (), actionDefinition.getAction (), context,
false, false);
      proxy.setMethod (actionDefinition.getMethod ());
      proxy.execute   ();
 
      return (proxy.getAction ());
    }
    catch (Exception e)
    {
      log.error ("Cannot invoke action '" + actionDefinition.getAction() +
"' in namespace '" + actionDefinition.getNamespace() + "'", e);
      throw e;
    }
  }
}
 
Regards,
 
Néstor Boscán

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message