Coding AJAX

Here’s a JQuery code example for calling resoa services using the auto-generated API’s:

// Defining namespaces
if (!org) org = {}; if (!org.resoa) org.resoa = {};
// Helper function for AJAX calls
org.resoa.getAJAXOptions = function (successHandler, errorHandler) {
	var options = {
		contentType : "application/json; charset=utf-8",
		dataType : "json", //service invocation is based on JSON
		url : "/service", //the URL of the resoa service domain 
		cache : false,
		type : "POST",
		complete : successHandler, //the success function
		error : errorHandler //the error function
	return options;
 //we instance request object, using the auto-generated Javascript library	 
 var student = new org.resoa.test.xsd.Student(); 
 //setting request values	 
 //set data to JSON representation of request object, call the Java service method 'exists' = student.toJson("store"); 
//we call in synchronized way
 ajaxOptions.async = false;
 //performing the AJAX request
 var xmlReq = $.ajax(ajaxOptions);
 //examining the result, which is the JSON representation of the Java response object
 if (org.resoa.test.xsd.Message.prototype.instanceOf(xmlReq.responseText)){
	 //creating Javascript Message object out of response JSON 
 	var msg = new org.resoa.test.xsd.Message(xmlReq.responseText);
	//continue with business logic by examining the response...	

Next an example for working with HTML forms:

<form name="editStudent" id="formedit" method="post" >
	<input type="text" name="Student_name" />
	<input type="text" name="User_name" />
	<input type="text" name="User_userid" />
	<input type="submit" value="Update" />

Here’s the javascript code for working with the form

//we request student data (wrapped by a function)
var student = org.resoa.test.requestStudent("Jon");
// select the HTML form, result is an array.
var formhandle = $("#formedit");
// fill the HTML form fields with object instance values

// the other way round, create a new object out of HTML form data
var newuser = new org.resoa.test.xsd.sub.User();
// we fill from Form