How To Perform Ajax Form Validation in Oracle Jdeveloper: 1. Introduction - What Is Ajax?
How To Perform Ajax Form Validation in Oracle Jdeveloper: 1. Introduction - What Is Ajax?
}
}
if (callback) callback(req.responseXML);
this.doGet = function() {
req.open("GET", url, true);
req.send(null);
}
Since Netscape and Microsoft use different XML parsers in their browsers, the first
function creates the HTTPrequest object and sets it to the appropriate type of object based
on what the browsers window environment calls for. The second function checks to see
that a) the request was completed (readyState=4) and b) data (status=200) was
received. The processRequest function then uses the servlets doGet section to process
the input. Note that the third argument in the req.open call is set to true. This identifies
that the request is asynchronous, meaning that it does not wait for further input from the
user, and continues processing the data.
The validateUserId() is what starts the AJAX process. This function is called when a key
is released from within the form on the page. The validateCallback function is called
when a response is received from the XMLHttpRequest. This function modifies the form
based on the response received from the servlet processing.
17. Change the servlet codes init, doPost, and doGet functions to match
the following:
import
import
import
import
java.io.*;
javax.servlet.*;
javax.servlet.http.*;
java.util.*;
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<valid>true</valid>");
} else {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<valid>false</valid>");
}
21. Success.
If everything works out correctly, the user is forwarded to the success.jsp file:
References
Example adapted from Real Time Form Validation with Ajax. Greg
Murray. 2006.
http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
Ajax Descriptions and function explanation from Professional AJAX. Zakas,
McPeak, Fawcett. 2006. Wiley Publishing.