Home arrow JavaScript arrow Page 3 - Intergrate DWR into Your Java Web Application
JAVASCRIPT

Intergrate DWR into Your Java Web Application


If you want to build your Ajax application around a JavaScript framework, you will need to use Direct Web Remoting code. This article shows you how. It is excerpted from Hack 43 from the book Ajax Hacks, written by Bruce W. Perry (O'Reilly; ISBN: 0596101694). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
July 24, 2008
TABLE OF CONTENTS:
  1. · Intergrate DWR into Your Java Web Application
  2. · Configuring the Application
  3. · Direct Web Remoting (DWR) for Java Jocks
  4. · Direct Web Remoting (DWR) for Java Jocks continued

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Intergrate DWR into Your Java Web Application - Direct Web Remoting (DWR) for Java Jocks
(Page 3 of 4 )

You may have to restart the Java web application for the servlet container to create a new instance of this DWR-related servlet.

You also have to create a simple XML file declaring the Java classes that you want to use from your client-side JavaScript code. Don’t worry, I’ll show you how to use the JavaScript objects that are bound to Java classes shortly! The file is named dwr.xml. Place this XML file in /WEB-INF/:

  <dwr>
     
<allow>
         
<create creator="new" javascript="JsDate">
             
<param name="class" value="java.util.Date"/>
         
</create>
         
<create creator="new" javascript="JsBikeBean">
             
<param name="class" value="com.parkerriver.BikeBean"/>
          </create>
      </allow>
  </dwr>

This XML states that the client-side JavaScript can use two Java classes remotely. The JavaScript objects that bind the client-side code remotely to the Java classes are namedJsDateandJsBikeBean. As part of the server-side preparations, you must have already developed the Java class
com.parkerriver.BikeBeanand installed it in your application.java.util.Dateis part of the Java software development kit; it’s not your own custom class.Date is already available as part of the Java virtual machine your server component is using.

TheBikeBeanclass file is typically stored in /WEB-INF/classes, as in /WEB-INF/classes/com/parkerriver/BikeBean.class.

This XML file binds the two JavaScript names to theDateandBikeBeanobjects, so that these objects are available to use in your client-side JavaScript. This means that JavaScript code can call all the public methods of these Java objects. But how is the JavaScript in the local web page connected to the remote Java instances running on the server? Figure 5-1 shows in general terms the path a JavaScript method call takes in DWR’s form of web remoting.

The web page that will use DWR contains thesescripttags, which connect the JavaScript code via the DWR servlet to the server code:

  <script type="text/javascript" src=
         
"/[name of web app]/dwr/interface/JsBean.js">
  </script>
  <script type="text/javascript" src=
          "/[name of web app]/dwr/interface/JsDate.js">
  </script>


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials