Wednesday, January 25, 2012

Direct Web Remoting (DWR)

Export Java to the browser and Javascript to the server

What is DWR?

An easy ajax for Java

DWR allows us to call Java Methods directly from Javascript and Javascript methods from Java
An Open Source licensed under Apache 2.0 license

How does DWR work?

A Java Servlet running on the server that processes requests and sends responses back to the browser.
Allows Javascript code in the browser to remotely invoke Java object methods on the server.
Converts objects between Java and Javascript representations so that they can be passed between the browser and the server.
Executes Javascript callback functions when asynchronous requests are processed by the server.

What does DWR comprise?

A Java Servlet running on the server
JavaScript running in the browser that sends requests and can dynamically update the webpage.

Interactivity


Creators / Converters

Creators create objects that live on the     server and have their methods remoted
Converters marshal parameters and return types
var r = Remote.method(param, callback);
Created object do tasks
Converted objects carry data

Reverse Ajax

Browser calling Server ; Server calling Browser
DWR allows Java code running on a server to use client side APIs to publish updates to the browser

Methods of pushing data to browser

Polling
-Browser makes request at regular intervals
Comet
-Server updating browser (scheduled by server)   
Piggyback
- Server sends updates to browser on browser’s next request

Turn on Reverse Ajax

-Turn Reverse Ajax on at client
-Initiate the server push
-Call JavaScript Methods/Add scripts to the browser from the server

DWRUtil Functions

(1) addOptions and removeAllOptions
(2) addRows and removeAllRows
(3)  getValue, getValues and getText
(4) setValue and setValues
(5) useLoadingMessage
 so on….

WebContextFactory Classes

WebContextFactory.get().getSession()
WebContextFactory.get().getHttpSession()
WebContextFactory.get().getScriptSession()
Related Posts Plugin for WordPress, Blogger...