You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Néstor Boscán <ne...@tcsapp.com.ve> on 2007/08/24 16:59:19 UTC

Struts 2 and DWR

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

Re: Struts 2 and DWR

Posted by Oleg Mikheev <mi...@bigfoot.com>.
Néstor Boscán wrote:
> 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.

Did you take a look at Struts 2 JSON Plugin?

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org