Direct Web Remoting : DWR

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + guest72599d guest72599d 2 years ago
    Good slide. I followed these steps and I configured successful!
Post a comment
Embed Video
Edit your comment Cancel

3 Favorites

Direct Web Remoting : DWR - Presentation Transcript

  1. DWR: Direct Web Remoting Hussain Fakhruddin [email_address]
  2. About Me
    • Open Source Advocate
    • Believe in coding with style
    • Blogger (hussulinux.blogspot.com)‏
    • Pure Vegetarian
  3. DWR:Agenda
    • What is DWR?
    • FAQ
    • Advantages
    • Tutorial
  4. DWR: Definition
    • Easy Ajax for Java. Export your Java code to a browser and include the results in your pages.
  5. DWR:Definition
    • In other words its nothing but An RPC library which makes it easy to call Java functions from JavaScript and to call JavaScript functions from Java (a.k.a Reverse Ajax).
  6. Some features
    • Virtually any data-structure between Java and Javascript (including binary file uploading and downloading)
    • exception handling
    • advanced CSRF(Cross site request forgery) protection
    • Integration with Spring and Guice
  7. JS to Java
  8. Java to JS: Reverse Ajax
    • allows Java code running on the server to find out what clients are viewing certain pages, and to send to them JavaScript, generated either manually or using a Java API
  9. Ingredients
    • 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
  10. Dynamic JS
    • DWR generates dynamic JS based on the Java Classes
    • The DWR Engine then does some Ajax magic to make it feel like the execution is happening on the browser, but in reality the server is executing the code and DWR is marshalling the data back and forwards.
  11. Advantages
    • Call Java Functions like RMI or Soap
    • Automatically create Java versions of JS
    • Expose business methods through JS
  12. Tutorial
    • Calculator Example
    • What you need?
    • Eclipse Step by Step
    • Run
  13. Calulator Example
    • We will write a Java class which has the following methods
    • int add(int a, int b);
    • int subtract(int a , int b);
    • int divide(int a, int b);
    • int multiply (int a, int b);
  14. What you need?
    • Download DWR.jar from :
      • http://getahead.org/dwr/download
  15. Add the Jar
  16. Add Dependency
    • Apache Commons: http:// commons.apache.org/downloads/download_logging.cgi
  17. Add Jars to Project
  18. Edit the web.xml <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
  19. Write your Business Logic package org.hussulinux.samples; public class Calculator { public Calculator() { } public int add( int a, int b) { return a + b; } public int subtract( int a, int b) { return a - b; } public int multiply( int a, int b) { return a * b; } public float divide( int a, int b) { if (b == 0) { return 0; } else return ( float )(( float )a / ( float )b); } }
  20. Add dwr.xml along with web.xml <!DOCTYPE dwr PUBLIC &quot;-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN&quot; &quot;http://getahead.org/dwr/dwr20.dtd&quot;> <dwr> <allow> <create creator=&quot;new&quot; javascript=&quot;Calculator&quot;> <param name=&quot;class&quot; value=&quot;org.hussulinux.samples.Calculator&quot;/> </create> </allow> </dwr>
  21. Open Default page to check
  22. Create front end
  23. index.jsp
    • <!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;>
    • <html>
    • <head>
    • <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;>
    • <title>My First DWR Example</title>
    • <script type='text/javascript' src='/CalculatorDWR/dwr/interface/Calculator.js'></script>
    • <script type='text/javascript' src='/CalculatorDWR/dwr/engine.js'></script>
    • <script type='text/javascript' src='/CalculatorDWR/dwr/util.js'></script>
    • </head>
    • <body>
    • A:<input type =&quot;text&quot; id=&quot;a&quot;><br/>
    • B:<input type =&quot;text&quot; id=&quot;b&quot;><br/>
    • <hr/>
    • <br/>
    • <input type =&quot;button&quot; value=&quot;Add&quot; onClick=&quot;Calculator.add(a.value,b.value,replyfunc)&quot; ><br/>
    • <input type =&quot;button&quot; value=&quot;Subtract&quot; onClick='Calculator.subtract($(&quot;a&quot;).value,$(&quot;b&quot;).value,replyfunc);' ><br/>
    • <input type =&quot;button&quot; value=&quot;Multiply&quot; onClick=&quot;Calculator.multiply(a.value,b.value,replyfunc)&quot; ><br/>
    • <input type =&quot;button&quot; value=&quot;Divide&quot; onClick=&quot;Calculator.divide(a.value,b.value,replyfunc)&quot; ><br/>
    • <script type=&quot;text/javascript&quot;>
    • var replyfunc=function(data){
    • if (data!=null && typeof data=='object')‏
    • alert(dwr.util.toDescriptiveString(data,2));
    • else
    • dwr.util.setValue(&quot;answerdiv&quot;, dwr.util.toDescriptiveString(data,1));
    • }
    • </script>
    • <hr/>
    • Answer = <div id =&quot;answerdiv&quot;> </div>
    • </body>
    • </html>
  24. Run
  25. Queries
  26. Thanks!
    • Joe Walker for starting this as open source project
    • TIBCO for supporting this project
    • You can email me at: [email_address]
    • Visit: http://hussulinux.blogspot.com

+ hussulinuxhussulinux, 2 years ago

custom

4413 views, 3 favs, 2 embeds more stats

Tutorial on how to DWR

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 4413
    • 4342 on SlideShare
    • 71 from embeds
  • Comments 1
  • Favorites 3
  • Downloads 87
Most viewed embeds
  • 63 views on http://hussulinux.blogspot.com
  • 8 views on http://blog.hussulinux.com

more

All embeds
  • 63 views on http://hussulinux.blogspot.com
  • 8 views on http://blog.hussulinux.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories