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