Dwr

19
@Andre_Mayer

description

 

Transcript of Dwr

Page 1: Dwr

@Andre_Mayer

Page 2: Dwr

wtf dwr?

• DWR¹ is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible.

• DWR is Easy Ajax² for Java

¹ Direct Web Remoting²Asynchronous Javascript and XML

Page 3: Dwr

Joe Walker

Page 4: Dwr

DWR consists of two main parts:– A Java Servlet running on the server that

processes requests and sends responses back to the browser.

– JavaScript running in the browser that sends requests and can dynamically update the webpage.

Page 5: Dwr

• DWR will generate the JavaScript to allow web browsers to call Java code. It can marshal virtually any data (using JSON) including collections, POJOs, XML and binary data like images and PDF files.

Page 6: Dwr

why use dwr?

DWR will give you productivity by enabling you call your java classes/methods with very few lines of javascript code

Page 7: Dwr

script browser sideAvoid complex XMLHttpRequest code, DOM manipulation, use DWR instead ;)

Page 8: Dwr
Page 9: Dwr
Page 10: Dwr
Page 11: Dwr

web.xml

Page 12: Dwr

dwr.xml

This definitions will generate javascript file in runtime named Chat.js

Page 13: Dwr
Page 14: Dwr

5

Page 15: Dwr

Chat.js

Page 16: Dwr

engine.js

Page 17: Dwr
Page 18: Dwr

it works!!

Page 19: Dwr

Advantages Disadvantages

Easy integration between Java and JavaScript

Only works in Java platform.

Integrates with Spring Beans; Marshalling: JSON may be unsafe unless you are using unpredictable URLs.

Real possibility to keep your MVC standard

Going through not standard way in “transfer technologies” using AJAX (old-fashion) instead web sockets (socket.io)

Integrates with leading Java Frameworks (Spring, JSF, Hibernate)

Debugging in console;

Cross-browser