advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
Rate this item | 0 users have rated this item.
 Print Print
 
Apply DWR to Data Validation in an AJAX Application
Learn how to use the open source Direct Web Remoting (DWR) library to dynamically generate JavaScript that includes a callback function parameter for web page updates in AJAX applications. 

advertisement
irect Web Remoting (DWR) is a Java open source library for developing AJAX applications that consists of two components: JavaScript running in the browser that sends requests and dynamically updates the web page with the response, and a servlet running on the server that processes requests and sends responses back to the browser. Remoting in DWR implies that Java class methods are remoted as JavaScript functions in the browser. DWR dynamically generates JavaScript corresponding to Java classes, and the JavaScript may be run in the browser just as any other JavaScript class library.

The generated JavaScript functions that correspond to Java class methods have a callback function as one of the parameters. The remote methods are invoked in the browser using the callback function, and the request is sent to the server using AJAX. When the request is complete AJAX is used to return a response to the browser. The callback function specified in the remote method is invoked with the data returned from the server, and the web page may be updated with the server response.

Download the DWR 1.1.4 JAR file, dwr.jar. Most browsers support DWR, and the application example described here will employ Microsoft Internet Explorer 6. DWR requires the Java Developer Kit (JDK) 1.3 or later and a servlet container that supports servlet specification 2.2 or later. Install a JDK if one is not installed already. JDK 1.5.0_10 was used for the application example discussed here.

DWR has been tested on these web servers: Tomcat, WebLogic, WebSphere, JBoss, Jetty, Resin, Sun ONE, and Glassfish. For this application use JBoss 4.05. Install JBoss 4.x, if it's not installed already. This DWR application will also use the MySQL database; installing MySQL 5.0 is therefore recommended. Create a database table named UserTable in the MySQL database using this script:

CREATE TABLE UserTable(userid VARCHAR(25) 
PRIMARY KEY, password VARCHAR(25));

INSERT INTO UserTable VALUES('dvohra', 'ajaxdwr');

INSERT INTO UserTable VALUES('jsmith', 'smith');
Configure JBoss with MySQL by copying the mysql-ds.xml file from the \JBoss\jboss-4.0.5.GA\docs\examples\jca directory to the \JBoss\jboss-4.0.5.GA\server\default\deploy directory. The MySQL datasource is specified as MySqlDS in the mysql-ds.xml file. Specify the connection URL and driver class:
<connection-url>jdbc:mysql://localhost:3306/test</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
A password is not required for the root user. Specify the user-name and password this way:
<user-name>root</user-name>
  <password></password>
Download the MySQL JDBC driver JAR file, mysql-connector-java-5.0.4-bin.jar, and copy it to the \jboss-4.0.5.GA\server\default\lib directory. For this discussion the DWR web application example was developed in the JDeveloper IDE. You can download the JDeveloper 10.1.3.2 ZIP file, and extract it to a separate directory to install it.

  Next Page: Create a DWR Application
Page 1: IntroductionPage 3: Common Creators
Page 2: Create a DWR ApplicationPage 4: Scripted Form
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES