Recently, I have integrated DWR (direct web remoting) in a spring application. There are some ways to do that, I'm going to explain only one, that uses spring support for namespaces introduced since Spring 2.0.
The first step is adding a new servlet in web.xml and map it to /dwr/*:
Second step is adding the namespace to our applicationContext:
This allows us to use DWR namespace for spring. Now, we are able to add the DWR controller to manage DWR requests:
We have setup dwr with spring, it's as easy as it seems. Supposing we have a service that returns a java.util.List of Article class. Article could be a simple bean like this:
To setup getLastArticles() as a remote ajax method with Spring we only have to annotate the related ArticleService spring bean:
That's all. We are telling DWR to convert our bean Article to JSON. And, only the method specified in dwr:include tag, is callable by ajax. We can call this method from any view in our web application. In the next episode, I will explain how.
Using DWR with Springframework (II)
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario