Hi,
After clicking the "Submit" button the Action class does the processing and calls the DAO to persist data in the DB.
An Ajax funtion is called which checks if the data submitted has changed status. The code is attached below
function postProcessStateChange(){ if("SUC"==document.forms[0].processingStatus.value) { var innerHtml = document.getElementById("processMessage").innerHTML; innerHtml = "<bean:message key="common.maintenanceMsg2"/> <bean:message key="trade.maintenance.tmsTradeId"/> : " + document.forms[0].tmsTradeId.value; document.getElementById("processMessage").innerHTML = innerHtml; } if("EXC"==document.forms[0].processingStatus.value) document.getElementById("processMessage").innerHTML = "<bean:message key="common.maintenanceMsg3"/>" ; if("ERR"==document.forms[0].processingStatus.value) document.getElementById("processMessage").innerHTML = "<bean:message key="common.maintenanceMsg4"/>" ; if("STA"==document.forms[0].processingStatus.value || "PUB"==document.forms[0].processingStatus.value) { if(statusTimeOut <= 60000){ document.getElementById("processMessage").innerHTML = "<img src='../images/refresh_active.gif'> <bean:message key="common.maintenanceMsg1"/>" ; if(vTradeType == 2) //TRANSRPT self.setTimeout('getRequestStatusTransrpt()', 5000); if(vTradeType == 1) //INTL self.setTimeout('getRequestStatusFiss()', 5000); if(vTradeType == 0) //DOMESTIC self.setTimeout('getRequestStatus()', 5000); } else document.getElementById("processMessage").innerHTML = "<bean:message key="common.maintenanceMsg4"/>" ; } } function getRequestStatus(){ alert("entered getRequestStatus"); statusTimeOut = statusTimeOut + 5000; var url = "<html:rewrite action='/trademaintenance' />?methodName=getRequestStatus"; retrieveURL(url, "","span"); alert("exiting getRequestStatus"); } function getRequestStatusFiss(){ statusTimeOut = statusTimeOut + 5000; var url = "<html:rewrite action='/trademaintenanceINTL' />?methodName=getRequestStatus"; retrieveURL(url, "","span"); } function getRequestStatusTransrpt(){ statusTimeOut = statusTimeOut + 5000; var url = "<html:rewrite action='/trademaintenanceTRANSRPT' />?methodName=getRequestStatus"; retrieveURL(url, "","span"); }
The ajax code is
function retrieveURL(url,nameOfFormToPost,ps) { parser = ps; //get the (form based) params to push up as part of the get request if(nameOfFormToPost != "") url=url+getFormAsString(nameOfFormToPost); //Do the Ajax call if (window.XMLHttpRequest) { // Non-IE browsers req = new XMLHttpRequest(); req.onreadystatechange = processStateChange; try { req.open("POST", url, true); //was get } catch (e) { alert("Problem Communicating with Server\n"+e); } req.send(null); } else if (window.ActiveXObject) { // IE //alert('Before Call'); req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = processStateChange; req.open("POST", url, true); req.send(); } } } /* * Set as the callback method for when XmlHttpRequest State Changes * used by retrieveUrl */ function processStateChange() { if (req.readyState == 4) { // Complete if (req.status == 200) { // OK response //alert("Ajax response:"+req.responseText); //Split the text response into Span elements spanElements = splitTextIntoSpan(req.responseText); //Use these span elements to update the page replaceExistingWithNewHtml(spanElements); //Implement this method in your local jsp for local or page specific changes after a ajax call postProcessStateChange() } else { alert("Problem with server response:\n " + req.statusText); } } alert("****exiting processStateChange"); } function splitTextIntoSpan(textToSplit){ //Split the document returnElements=textToSplit.split("</"+parser+">") //Process each of the elements for ( var i=returnElements.length-1; i>=0; --i ){ //Remove everything before the 1st span spanPos = returnElements[i].indexOf("<"+parser); //if we find a match , take out everything before the span if(spanPos>0){ subString=returnElements[i].substring(spanPos); returnElements[i]=subString; } } return returnElements; } function replaceExistingWithNewHtml(newTextElements){ alert("new text elements"+newTextElements); //loop through newTextElements for ( var i=newTextElements.length-1; i>=0; --i ){ //check that this begins with <span if(newTextElements[i].indexOf("<"+parser)>-1){ //get the name - between the 1st and 2nd quote mark startNamePos=newTextElements[i].indexOf('"')+1; endNamePos=newTextElements[i].indexOf('"',startNamePos); name=newTextElements[i].substring(startNamePos,endNamePos); //get the content - everything after the first > mark startContentPos=newTextElements[i].indexOf('>')+1; content=newTextElements[i].substring(startContentPos); //Now update the existing Document with this element //check that this element exists in the document if(document.getElementById(name)){ //alert("Replacing Element:"+name); //alert("containing"+document.getElementById(name).innerHTML); //alert("with"+content); document.getElementById(name).innerHTML = content; } else { alert("Element:"+name+"not found in existing document"); } } } alert("leaning replaceExistingWithNewHtml"); }
Once the call return with the message being displayed in the jsp. I can't used any button "Submit" or "Reset".
I have a requirement whrer I need to reset the all fields one the processing
is completed for one trade.