I basically created a DWRAction class based on the one that WebWorks used and I use it extensively on my Struts 2 applications:
import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionProxyFactory; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts2.dispatcher.Dispatcher; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.directwebremoting.webwork.ActionDefinition; 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; } } } You must configure this class and ActionDefinition in you dwr.xml file and any Actions you wish to invoke <create creator="none" javascript="DWRAction"> <param name="class" value="ve.com.movilnet.rtb.vista.dwr.DWRAction"/> </create> <convert converter="bean" match="org.directwebremoting.webwork.ActionDefinition"> <param name="include" value="namespace,action,method,executeResult"/> </convert> <convert converter="bean" match="MyAction"> <param name="include" value="fieldErrors, actionErrors "/> </convert> Also is important that the Struts 2 Filter applies to the URL /dwr/*. So with this code you can invoke any Action in your application, and return information from that Action. The validation framework will work here too, returning any validation errors in the fieldErrors attribute before reaching the action method. You can put validations in the validation framework or you're validation method, or you can do AJAX invocations to retrieve data. Regards, Néstor Boscán -----Mensaje original----- De: lllewell [mailto:laura.llewel...@gfs.com] Enviado el: Friday, February 13, 2009 12:13 PM Para: user@struts.apache.org Asunto: AJAX with DWR but without DOJO? Greetings all - I inherited a struts2 webapp that is using the "simple" theme all the way through. I'd like to add some Ajax validation to one of the pages using DWR. I'm interested in doing this without DOJO (theme="ajax"). I see an example of how to do Prototype validation without DOJO here: http://struts.apache.org/2.1.6/docs/ajax-validation.html . I can use that as a basis, but I'm wondering if anyone has done something similar using DWR that you would be willing to share, or links to other reference materials that would help me out. I have googled this extensively and haven't had much luck. I'm planning to use Struts 2.1.6 and DWR 2.0.x (since DWR 3 isn't ready for prime time yet). Thanks in advance! Laura -- View this message in context: http://www.nabble.com/AJAX-with-DWR-but-without-DOJO--tp22000168p22000168.ht ml Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org