SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Introducing DWR (Direct Web
                 Remoting)
       BOOBUN Ashish – 20th November 2009
Agenda
   Ajax
   Introduction to DWR
   Steps to create a DWR web application
   DWR configurations
   Callback Mechanism
   Converters
   DWR .js file
   Comet with DWR
   Advantages
AJAX
   Asynchronous JavaScript and XML
   Collection of technologies used on client site to develop interactive
    web application
        Document Object Model (DOM)
        XML, JSON, HTML, plain text
        XMLHttpRequest (XHR) – for asynchronous
         communication
        JavaScript
   Retrieve data asynchronously from server while preserving the
    current state of the user interface
   Services on server had to be accessed via URL, with request
    parameters. For e.g. http://www.google.co.uk/search?q=ajax
AJAX in Action




                 Google is intelligent
DWR Explained
   An open source library that resides between Java and JavaScript
    code.
   An implementation of AJAX in Java.
   Enables Java code on the server and JavaScript code in a browser
    to interact and call each other as simply as possible.
      Making the process resemble as a “Remote Procedure call”.
      Handles the low-level communication using the
        XMLHttpRequest object.
   DWR consists of two parts:
      A Java Servlet on the server to capture DWR’s request and
       sends response back to the browser
      JavaScript on browser side that handles request and response
       and dynamically update part of the web page accordingly.
Why DWR - NO to boiler-plate code
Steps to create a DWR-enable AJAX
application
   Add maven dependency for DWR
   Add DWR servlet and DWR servlet mapping in web.xml
   Write Java service class and its corresponding methods
   Include DWR configuration (in spring bean configuration
    file, if using DWR v2.x. Else specify in dwr.xml if using
    v1.x) to state what classes and method of the backend
    will be exposed.
       Note that we will be integrating DWR with Spring
   Write client-side JavaScript code and invoke methods
    that has been exposed in an RPC style.
Requirements
   Maven Dependency




   Web.xml
DWR Configuration




   The tag <dwr:configuration> must be present (if defining
    dwr configurations in the spring bean configuration file
    and not in dwr.xml file), even if it’s empty.
Client-side JavaScript code

 DWR includes 2 plain JavaScript files: engine.js (compulsory) and util.js
  (optional).
 OutboundService.js is a dynamically generated .js file that interfaces with
  engine.js to invoke methods exposed on the server.




   Notice the RPC-style syntax – OutboundService.getOutboundList()
Handling Asynchronous Calls
 Data is available some time after the initial call was made.
 How to combine the asynchronous nature of Ajax with the
  synchronous nature of normal Java method calls?
 DWR provides call-back method mechanism.
 Call-back function is called when data is received from the server.
Converters
   Marshall data when it is sent between client and server
   DWR provides the following converters
       Basic and Date Converters (By default it is enable)
       Bean and Object converters - convert Java Beans and
        POJOs to and from JavaScript objects
       Array Converters
       Collection Converters
       DOM Converters

   E.g. <dwr:convert type="bean
    class="com.tnt.express.mww.walldisplay.dto
    .Outbound" />
DWR .js files
   Engine.js
      Used to marshal calls from the dynamically generated interface
       JavaScript function, so it is needed wherever DWR is used.
      Also contain set option methods related to timeout, errorHandler,
       warningHandler.

   Util.js
      Contains a number of utility functions to help you update your
        web pages with JavaScript data
      Can use it outside of DWR scope

      E.g. of utility methods
            $(id) – document.getElementById(id)
            DWRUtil.getValue(id) – get the value of the HTML element with id.
Comet with DWR
   Long-lived HTTP
   Reversing the usual communication flow
   Allow the server to start answering the browser’s
    request for information very slowly by pushing data to
    the browser without the latter ever explicitly requesting it
   Disadvantage:
       Server can be overloaded with too many connection
       Server takes too much time to push data in IE 6 browser
Advantages of using DWR
   DWR uses an “RPC-style mechanism” whereas almost all other forms
    of AJAX take a URL-based approach.
      DWR eliminate the needs of having each method (service) on the
        server to be addressable via URL.
   No need to map parameters and return value to HTML input form and
    responses respectively.
   DWR is packaged with JavaScript utility functions that allows you to
    dynamically modify HTML tags.
   The code for the service class is a simple POJO, and not tied to HTTP
    at all. Easier to unit test.
                                      You can write AJAX web app at
                                       the same rate as Jack Bauer
                                              works at CTU
   Codes is simpler, less verbose.
Question???

Weitere ähnliche Inhalte

Andere mochten auch

Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28Valdinho Pereira
 
Apresentação VRaptor 3
Apresentação VRaptor 3Apresentação VRaptor 3
Apresentação VRaptor 3Alabê Duarte
 
Aula Introdução a VRaptor 4 - Pós Java UTFPR
Aula Introdução a VRaptor 4 - Pós Java UTFPRAula Introdução a VRaptor 4 - Pós Java UTFPR
Aula Introdução a VRaptor 4 - Pós Java UTFPRAndré Luiz Forchesatto
 
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...Carlos A. Junior Spohr Poletto
 
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVAVRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVAYelken Heckman Ferreira Gonzales
 
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3André Luiz Forchesatto
 
VRaptor - Ciclo CASIN 2011
VRaptor - Ciclo CASIN 2011VRaptor - Ciclo CASIN 2011
VRaptor - Ciclo CASIN 2011Daniel Kist
 

Andere mochten auch (11)

Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28
 
Apresentação VRaptor 3
Apresentação VRaptor 3Apresentação VRaptor 3
Apresentação VRaptor 3
 
Palestra VRaptor 3
Palestra VRaptor 3Palestra VRaptor 3
Palestra VRaptor 3
 
Apresentação sobre VRaptor na Campus Recife 2014
Apresentação sobre VRaptor na Campus Recife 2014Apresentação sobre VRaptor na Campus Recife 2014
Apresentação sobre VRaptor na Campus Recife 2014
 
Introdução ao vraptor
Introdução ao vraptorIntrodução ao vraptor
Introdução ao vraptor
 
Aula Introdução a VRaptor 4 - Pós Java UTFPR
Aula Introdução a VRaptor 4 - Pós Java UTFPRAula Introdução a VRaptor 4 - Pós Java UTFPR
Aula Introdução a VRaptor 4 - Pós Java UTFPR
 
Java Web Fácil com VRaptor
Java Web Fácil com VRaptorJava Web Fácil com VRaptor
Java Web Fácil com VRaptor
 
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
 
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVAVRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
 
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
 
VRaptor - Ciclo CASIN 2011
VRaptor - Ciclo CASIN 2011VRaptor - Ciclo CASIN 2011
VRaptor - Ciclo CASIN 2011
 

Ähnlich wie Introducing dwr (direct web remoting)

MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)Daniel Bryant
 
Web services in java
Web services in javaWeb services in java
Web services in javamaabujji
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-servicesAravindharamanan S
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applicationsdominion
 
Ajax with DWR
Ajax with DWRAjax with DWR
Ajax with DWRgouthamrv
 
Web service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National WokshopWeb service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National WokshopNishikant Taksande
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
Direct Web Remoting : DWR
Direct Web Remoting : DWRDirect Web Remoting : DWR
Direct Web Remoting : DWRhussulinux
 
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesJava Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesIMC Institute
 

Ähnlich wie Introducing dwr (direct web remoting) (20)

11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
Dwr
DwrDwr
Dwr
 
Dwr
DwrDwr
Dwr
 
SCDJWS 5. JAX-WS
SCDJWS 5. JAX-WSSCDJWS 5. JAX-WS
SCDJWS 5. JAX-WS
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
 
Web services in java
Web services in javaWeb services in java
Web services in java
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-services
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Ajax with DWR
Ajax with DWRAjax with DWR
Ajax with DWR
 
Web service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National WokshopWeb service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National Wokshop
 
Day7
Day7Day7
Day7
 
Servlets
ServletsServlets
Servlets
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Ntg web services
Ntg   web servicesNtg   web services
Ntg web services
 
CHC 2009 - The Ccls Approach To Building M Pages
CHC 2009 - The Ccls Approach To Building M PagesCHC 2009 - The Ccls Approach To Building M Pages
CHC 2009 - The Ccls Approach To Building M Pages
 
Signal r
Signal rSignal r
Signal r
 
Direct Web Remoting : DWR
Direct Web Remoting : DWRDirect Web Remoting : DWR
Direct Web Remoting : DWR
 
Dot net training bangalore
Dot net training bangaloreDot net training bangalore
Dot net training bangalore
 
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesJava Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web Services
 

Kürzlich hochgeladen

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Introducing dwr (direct web remoting)

  • 1. Introducing DWR (Direct Web Remoting) BOOBUN Ashish – 20th November 2009
  • 2. Agenda  Ajax  Introduction to DWR  Steps to create a DWR web application  DWR configurations  Callback Mechanism  Converters  DWR .js file  Comet with DWR  Advantages
  • 3. AJAX  Asynchronous JavaScript and XML  Collection of technologies used on client site to develop interactive web application  Document Object Model (DOM)  XML, JSON, HTML, plain text  XMLHttpRequest (XHR) – for asynchronous communication  JavaScript  Retrieve data asynchronously from server while preserving the current state of the user interface  Services on server had to be accessed via URL, with request parameters. For e.g. http://www.google.co.uk/search?q=ajax
  • 4. AJAX in Action Google is intelligent
  • 5. DWR Explained  An open source library that resides between Java and JavaScript code.  An implementation of AJAX in Java.  Enables Java code on the server and JavaScript code in a browser to interact and call each other as simply as possible.  Making the process resemble as a “Remote Procedure call”.  Handles the low-level communication using the XMLHttpRequest object.  DWR consists of two parts:  A Java Servlet on the server to capture DWR’s request and sends response back to the browser  JavaScript on browser side that handles request and response and dynamically update part of the web page accordingly.
  • 6. Why DWR - NO to boiler-plate code
  • 7. Steps to create a DWR-enable AJAX application  Add maven dependency for DWR  Add DWR servlet and DWR servlet mapping in web.xml  Write Java service class and its corresponding methods  Include DWR configuration (in spring bean configuration file, if using DWR v2.x. Else specify in dwr.xml if using v1.x) to state what classes and method of the backend will be exposed.  Note that we will be integrating DWR with Spring  Write client-side JavaScript code and invoke methods that has been exposed in an RPC style.
  • 8. Requirements  Maven Dependency  Web.xml
  • 9. DWR Configuration  The tag <dwr:configuration> must be present (if defining dwr configurations in the spring bean configuration file and not in dwr.xml file), even if it’s empty.
  • 10. Client-side JavaScript code  DWR includes 2 plain JavaScript files: engine.js (compulsory) and util.js (optional).  OutboundService.js is a dynamically generated .js file that interfaces with engine.js to invoke methods exposed on the server.  Notice the RPC-style syntax – OutboundService.getOutboundList()
  • 11. Handling Asynchronous Calls  Data is available some time after the initial call was made.  How to combine the asynchronous nature of Ajax with the synchronous nature of normal Java method calls?  DWR provides call-back method mechanism.  Call-back function is called when data is received from the server.
  • 12. Converters  Marshall data when it is sent between client and server  DWR provides the following converters  Basic and Date Converters (By default it is enable)  Bean and Object converters - convert Java Beans and POJOs to and from JavaScript objects  Array Converters  Collection Converters  DOM Converters  E.g. <dwr:convert type="bean class="com.tnt.express.mww.walldisplay.dto .Outbound" />
  • 13. DWR .js files  Engine.js  Used to marshal calls from the dynamically generated interface JavaScript function, so it is needed wherever DWR is used.  Also contain set option methods related to timeout, errorHandler, warningHandler.  Util.js  Contains a number of utility functions to help you update your web pages with JavaScript data  Can use it outside of DWR scope  E.g. of utility methods  $(id) – document.getElementById(id)  DWRUtil.getValue(id) – get the value of the HTML element with id.
  • 14. Comet with DWR  Long-lived HTTP  Reversing the usual communication flow  Allow the server to start answering the browser’s request for information very slowly by pushing data to the browser without the latter ever explicitly requesting it  Disadvantage:  Server can be overloaded with too many connection  Server takes too much time to push data in IE 6 browser
  • 15. Advantages of using DWR  DWR uses an “RPC-style mechanism” whereas almost all other forms of AJAX take a URL-based approach.  DWR eliminate the needs of having each method (service) on the server to be addressable via URL.  No need to map parameters and return value to HTML input form and responses respectively.  DWR is packaged with JavaScript utility functions that allows you to dynamically modify HTML tags.  The code for the service class is a simple POJO, and not tied to HTTP at all. Easier to unit test. You can write AJAX web app at the same rate as Jack Bauer works at CTU  Codes is simpler, less verbose.