Similar presentations

2
What is Direct Web Remoting? DWR is AJAX and XMLHttpRequest made easy

3
Foundation of DWR - XMLHttpRequest APIs available in Javascript and VBScript Can transfer XML to and from the browser Allows dynamic updates of pages without refreshing the entire page l No plugins required Example: Google SuggestGoogle Suggest

5
DWR Features Simplifies AJAX and XMLHttpRequest l APIs for calling server objects – no need to learn complex XMLHttpRequest JavaScript code Handles marshalling/unmarshalling of parameters l Can convert primitive types, and several collections & more complex types l Developer can create custom converters Provides a framework to expose Java beans as remote objects Can access beans in a users session, or new beans created in a variety of ways Simple setup Works with existing frameworks, does not replace them l No special interfaces/classes required to be implemented or extended

6
More Technical Features Call batching l Can send many calls in a single round-trip request l Supports call ordering Custom error handling Remoting hooks l Get notified right before or right after a call – change state of forms, etc Remoting method choice l XMLHttpRequest or IFrame Can select GET or POST for requests

7
Possible Uses of DWR Scrolling a map or other large image l Google Maps Google Maps Dynamic form validation Asynchronous population of lists/text Anywhere you want to update portions of a web page without affecting other content l See DWR ExamplesDWR Examples Biggest advantage to user: Web page begins to work more like desktop application

15
DWREngine - Batching Call batching - beginBatch and endBatch DWREngine.beginBatch(); ExposedJavaObject.aMethod(); ExposedJavaObject.anotherMethod(); DWREngine.endBatch(); Executes aMethod and anotherMethod in a single round-trip call to the server As with other calls, these are asynchronous

16
DWREngine - Call Ordering By default, all calls are asynchronous, so may not return in the order they were sent Can be altered to be synchronous DWREngine.setOrdered(true); ExposedJavaObject.aMethod(); ExposedJavaObject.anotherMethod(); This will wait for completion of aMethod before making the call to anotherMethod Can affect application performance and end-user experience

19
DWREngine – Remoting Options Write code to gracefully fall back if javascript is not available/enabled: DWREngine.setMethod(newmethod); l newmethod should be DWREngine.XMLHttpRequest (default) or DWREngine.IFrame Select GET or POST for sending requests DWREngine.setVerb(newverb); l newverb should be GET or POST (default)

20
Client Component Details – Interface Dynamically-generated JavaScript for each exposed bean Required to use a particular exposed bean Included in jsp/html page: Exposes an object with the name of your Java object Methods match the server-side object

26
JSON-RPC Drawbacks JSON-RPC is more complex than DWR l Steeper learning curve for developers l More client-side coding required of developer DWR project is more active l Features and fixes are being released more frequently l JSON is concentrating more on developing JavaScript APIs (catching up with DWR) No Spring integration