DWR and Struts Error - dwr is undefined...

hi all,

i had integreated DWR in my struts application.. it was working few days back.. now when i access the page which is integratted DWR is giving me an error "dwr is undefined"...

also i am getting the default error message on the browser when i install sample dwr package...

i am using tomcat 5.5., java 1.5 .. i did not change anyting on sever....

what to do?
LVL 36
Loganathan NatarajanLAMP DeveloperAsked:
Who is Participating?
 
TimYatesCommented:
You seem to have a mismash of v1.0 and v2.0 calls in there...

eg:

      DWREngine.setErrorHandler(function(message) { alert(message); });

in v2.0 is:

      dwr.engine.setErrorHandler( function(message) { alert(message); } ) ;

Where did you get the file from?  Is it out of the v1.0 download?

Where's that call you said was failing before?
0
 
TimYatesCommented:
What version of DWR are you using?

Can you show your script including tags from your jsps?

I believe from v1 to v2 the way you call the dwr javascript changed name, so I am guessing this is your problem
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
oh ok.. i will check it... and let u know
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
TimYatesCommented:
Also, can you post the line which is causing the error?  (if you still get an error after checking the version of dwr is right on the webserver?) :-)

Cheers

(and fingers crossed)

Tim
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
error occurs in dwr.util.removeAllRows ...

i think i am using DWR 1.0 ... my dwr.xml top lines are,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">

<dwr>

      <allow>
            <create creator="new" javascript="ChildEditAction">
                  <param name="class" value="com.isw.struts.action.ChildEditAction" />
            

etc.,,,
// Used to fill the table using an asynchronous request
function fillSponsorsLookup(startWith) {	
	/* Asynchronous rquest to Server for the results */
	var sponsors=null;
	SponsorManager.getSponsorBeginsWith(startWith, function (sponsors) {
		dwr.util.removeAllRows("sponsorsTable", {filter:function (tr) {
			return (tr.id != "pattern");
		}});
    	// Delete all the rows except for the "pattern" row
		
    	// Create a new set cloned from the pattern row
		var sponsor, id;
		if (sponsors.length == 0) 
		{
			//alert("There are no records matching your search ! ");
			var el=$('noRecords');
			el.style.visibility = "visible";
			$('searchProgress').style.visibility="hidden";
			return false;
		}
		else
		{
			var el=$('noRecords');
			el.style.visibility = "hidden"
		}	
		
		for (var i = 0; i < sponsors.length; i++) 
		{
			sponsor = sponsors[i];
			id = sponsor.spoId;
			dwr.util.cloneNode("pattern", {idSuffix:id});
			dwr.util.setValue("spName" + id, (sponsor.spoLastname+" "+sponsor.spoFirstname));
			//$("chk").value = id;
			$("pattern" + id).style.display = "";
		}
		$('searchProgress').style.visibility="hidden";
	});
}

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
actually everthing was working perfect two days before.. suddenly now the dwr undefined error is occuring.. ..also i am getting the below error when i run the dwr testing program...
*************************************
Missing DWR Javascript Functions
This is a fairly advanced page that tests DWR to check that everything is setup properly for you.

It appears that you may be attempting to run DWR outside a servlet container (possibly using a file: URL). We think this because this page has missing Javascript functions that should have been produced by DWR. To fix the problem please use DWR from within a servlet container.

If this is not the cause of the problem, please report it to the DWR mailing list, including your browser, server, OS configuration and any error messages that appeared either in the browser (including the Javascript console if one exists) and the server console log.

DWR is testing installation ...
This is a fairly advanced page that tests DWR. If you can see this message for a prolonged period of time then you should check the following:

Can you see the test pages?
If not it is likely that DWR has not deployed in your web server properly; Check the web server console and log files for error messages.
If you can see the test pages then DWR is loaded but is something is preventing DWR working. Check your browser Javascript console for error messages, or see the main DWR website for more information.
If none of these steps fixes the error, please report it to the DWR mailing list, including your browser, server, OS configuration and any error messages that appeared either in the browser (including the Javascript console if one exists) and the server console log.

For general information about DWR see:

The main DWR website.
Joe Walker's blog.
The DWR page at Wikipedia.
0
 
TimYatesCommented:
Try this...  This is the v1 remove all rows...

I *think* the dwr.util.* stuff came with v2.0
DWRUtil.removeAllRows( "sponsorsTable", { filter: function( tr ) {
                       return (tr.id != "pattern");
                     } } ) ;

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
sorry.. i'm using DWR 2.0.. as my code is correct with the line... will there be any installation problem..?
0
 
TimYatesCommented:
Not sure what you mean by "installation problem"?

Are you loading the dwr javascript before you load your own javascript?

Are you sure all the dwr javascript files are loading?

Can you post the <script> tags from your page?
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
the below are the sample code,
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>DWR - Test Home</title>
  <script type='text/javascript' src='dwr/interface/Test.js'></script>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>
  <script>
    function init() {
      // This turns off the no-javascript message
      document.getElementById("start").style.display = "none";
	alert(window.DWREngine);
alert(window.DWRUtil);
 
      // This checks for file: URLs and loading problems
      if (window.DWREngine == null || window.DWRUtil == null) {
        document.getElementById("file").style.display = "block";
        return;
      }
      // DWR setup
      DWREngine.setErrorHandler(function(message) { alert(message); });
      DWREngine.setWarningHandler(function(message) { alert(message); });
      DWRUtil.useLoadingMessage();
      // Turn on the generic error div
      $("error").style.display = "block";
      // Load a message from the server
      Test.getInsert(load);
    }
 
    function load(data) {
      $("error").style.display = "none";
      DWRUtil.setValue("reply", data);
      $("reply").style.display = "block";
    }
  </script>
</head>
 
<body onload="init()">
 
<div id="start">
  <h1>DWR is testing installation ...</h1>
  <p>
    DWR uses Javascript to make some initial checks. If you can see this message
    then either you are a very fast reader, or Javascript is not working
    properly in your browser.
  </p>
  <p>
    Since AJAX requires Javascript, you will need to enable Javascript in your
    browser before you can test DWR. Some very old browsers like IE 4.0 have
    very out of date support for Javascript and are currently unsupported.
    Please upgrade your browser.
  </p>
</div>
 
<div id="reply" style="display:none;">
  <h1>DWR is partially working</h1>
  <p>
    DWR has received test data from the server, however for some reason this
    data was mangled. Please report this error to the
    <a href="http://getahead.ltd.uk/dwr/support">DWR mailing list</a>, including
    your browser, server, OS configuration and any error messages that appeared
    either in the browser (including the Javascript console if one exists) and
    the server console log.
  </p>
</div>
 
<div id="file" style="display:none;">
  <h1>Missing DWR Javascript Functions</h1>
  <p>
    This is a fairly advanced page that tests DWR to check that everything is
    setup properly for you.
  </p>
  <p>
    It appears that you may be attempting to run DWR outside a servlet container
    (possibly using a file: URL). We think this because this page has missing
    Javascript functions that should have been produced by DWR. To fix the
    problem please use DWR from within a servlet container.
  </p>
  <p>
    If this is not the cause of the problem, please report it to the
    <a href="http://getahead.ltd.uk/dwr/support">DWR mailing list</a>, including
    your browser, server, OS configuration and any error messages that appeared
    either in the browser (including the Javascript console if one exists) and
    the server console log.
  </p>
</div>
 
<div id="error" style="display:none;">
  <h1>DWR is testing installation ...</h1>
  <p>
    This is a fairly advanced page that tests DWR. If you can see this message
    for a prolonged period of time then you should check the following:
  </p>
  <ul>
    <li>
      Can you see the <a href="dwr/">test pages</a>?<br/>
      If not it is likely that DWR has not deployed in your web server properly;
      Check the web server console and log files for error messages.
    </li>
    <li>
      If you can see the <a href="dwr/">test pages</a> then DWR is loaded but is
      something is preventing DWR working. Check your browser Javascript console
      for error messages, or see the <a href="http://getahead.ltd.uk">main
      DWR website</a> for more information.
    </li>
  </ul>
  <p>
    If none of these steps fixes the error, please report it to the
    <a href="http://getahead.ltd.uk/dwr/support">DWR mailing list</a>, including
    your browser, server, OS configuration and any error messages that appeared
    either in the browser (including the Javascript console if one exists) and
    the server console log.
  </p>
</div>
 
<div id="more">
  <p>
    For general information about DWR see:
  </p>
  <ul>
    <li>The <a href="http://getahead.ltd.uk/dwr/">main DWR website</a>.</li>
    <li><a href="http://getahead.ltd.uk/blog/joe/">Joe Walker's blog</a>.</li>
    <li>The <a href="http://en.wikipedia.org/wiki/DWR">DWR page</a> at Wikipedia.</li>
  </ul>
</div>
 
</body>
</html>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
hi TimYates... thanks for helping me to fix this issue...

the below is my actual error page code... when i enter some value in the text box to get search results.... (LOOK-UP feature)



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="/SITE/includes/SITE_style.css" rel="stylesheet" type="text/css">
</head>
<script type='text/javascript' src='/SITE/dwr/engine.js'></script>
<script type='text/javascript' src='/SITE/dwr/util.js'></script>
<script type='text/javascript' src='/SITE/dwr/interface/SponsorManager.js'> </script>
<script type='text/javascript' src='/SITE/dwr/interface/SponsorEditForm.js'></script>
<script type='text/javascript' src='/SITE/dwr/interface/FundEditAction.js'> </script>
<script type='text/javascript' src='/SITE/dwr/interface/FundEditForm.js'></script>
 
<script language="javascript" src="/SITE/includes/lookup.js"></script>
<body>
     <script language="javascript" type="text/javascript">
 
 
 function Project( ) {
	var frm=document.addFund;
	
	if(frm.select2.value=="PR")
	{
		frm.select3.disabled=false;
	}
	else
	{
		frm.select3.disabled=true;
		frm.select3.value="";
	}
 }
 
 
function formsubmit(frmName)
{
	if(TextValidate(frmName.funPaymentdate, '<bean:message key="fund.paymentDate"/>') == false) return false;
	if(validateCombo('funSponsorid.spoId','<bean:message key="fund.selectSponsor"/>')==false)return false;
	if(validateCombo('funPaymentmodeid.pmtId','<bean:message key="fund.selectPaymentMode"/>')==false)return false;
	if(TextValidate(frmName.strfunAmount, '<bean:message key="fund.amountOnly"/>') == false) return false;
	if(TextValidate(frmName.funPurpose, '<bean:message key="fund.purpose"/>') == false) return false;																		
	if(document.fundEditForm.funPurpose.value == 'Select')
	{
		alert('<bean:message key="fund.selectPurpose"/>');
		return false;
	}
	if(CurrentdateValidate(frmName.funPaymentdate,'<bean:message key="fund.paymentDate"/>') == false) return false
	var itemChecked=false;
	for(var i=0; i<frmName.funReciptneeded.length; i++)
	{
		if(frmName.funReciptneeded[i].checked)
		{
			itemChecked=true;
			break;
		}
	}
	if(document.fundEditForm.funPurpose.value == 'Project')
		if(validateCombo('projectId','<bean:message key="fund.selectProject"/>')==false)return false;	
	//if(document.fundEditForm.projectId.value != 'Select' && document.fundEditForm.funPurpose.value != 'Individual Sponsorship' && document.fundEditForm.funPurpose.value != 'Collective Sponsorship' && document.fundEditForm.funPurpose.value != 'Donation')	
		//if(validateCombo('funProjectid.sproId','Please Enter the Sub-Project')==false)return false;
	if(!itemChecked)
	{
		alert('<bean:message key="fund.selectReceiptNeeded"/>');
		return false;
	}
	
	
	frmName.submit();
	frmName.Printbutton.disabled = true;
}
 
 
function validateCombo(cntrlName,msg){
	var cmbIndex=0;
	var frm = document.fundEditForm;  
	cmbIndex = getComboIndex(frm,cntrlName);
	if(frm.elements[cmbIndex].value==0 || frm.elements[cmbIndex].value.length==0){
		frm.elements[cmbIndex].focus();
		alert(msg);
		return false;
	}	
}
 
function check()
{
	var name = "Project";
	if(document.fundEditForm.funPurpose.value == name)
	{
		var cmbIndex=0;
		var cntrlName1 = "projectId";
		var cntrlName2 = "funProjectid.sproId";
		var frm = document.fundEditForm;  
		cmbIndex = getComboIndex(frm,cntrlName1);
		frm.elements[cmbIndex].disabled=false;
		frm.elements[cmbIndex].value = 0;
		cmbIndex = getComboIndex(frm,cntrlName2);
		frm.elements[cmbIndex].disabled=false;
		frm.elements[cmbIndex].value = 0;								
		return false;
	}
	else
	{
		var cmbIndex=0;
		var cntrlName1 = "projectId";
		var cntrlName2 = "funProjectid.sproId";
		var frm = document.fundEditForm;  
		cmbIndex = getComboIndex(frm,cntrlName1);
		frm.elements[cmbIndex].disabled=true;
		frm.elements[cmbIndex].value = 0;
		cmbIndex = getComboIndex(frm,cntrlName2);
		frm.elements[cmbIndex].disabled=true;
		frm.elements[cmbIndex].value = 0;								
		return false;
	}
}
 
 
function OpenWindow(strHref,windowname) {
	window.open("/SITE/fund/fund_printreceipt.jsp", "SITE",
	"toolbar=no,resizable=0,menubar=no,location=no,scrollbars=yes,width=600,height=175,top=0,left=30");		
}
 
 
function AmountCheck(txtCtrl) {
	Remove_Spaces(txtCtrl);
	var fLength = txtCtrl.value.length;
	if (fLength == 0) {
		return false;
	}	
	// Required but check Empty
	if (txtCtrl.value == "" || isNaN(txtCtrl.value)){ 	
			alert('<bean:message key="fund.validAmount"/>');		
			txtCtrl.focus();
			txtCtrl.select();
			return false;	
	}		
}
 
 
function onlyDigitsAnddot()
{
	var s = document.fundEditForm.strfunAmount.value.split('.');
	if (s.length > 2){
		alert('<bean:message key="fund.morethan1dot"/>');
		fundEditForm.strfunAmount.focus();
		return false;
	}
	if(s.length>1)
	{
			if(s[1].length > 2){
				alert('<bean:message key="fund.onlytwodegits"/>');
				fundEditForm.strfunAmount.focus();
				return false;
			}
			if(s[1].length < 2){
				alert('<bean:message key="fund.twodigits"/>');
				fundEditForm.strfunAmount.focus();
				return false;
			}
			if(s[0].length > 7) {
				alert('<bean:message key="fund.budgetamount"/>');
				fundEditForm.strfunAmount.focus();
				return false;
			}
	}
 
}
 
 
function onlyDigitsAnddot()
{
 
	var s = document.fundEditForm.strfunAmount.value.split('.');
	if (s.length > 2){
		alert('<bean:message key="fund.morethan1dot"/>');
		document.fundEditForm.strfunAmount.focus();
		return false;
	}
	if(s.length>1)
	{
			if(s[1].length > 2){
				alert('<bean:message key="fund.onlytwodegits"/>');
				document.fundEditForm.strfunAmount.focus();
				return false;
			}
			if(s[1].length < 2){
				alert('<bean:message key="fund.twodigits"/>');
				document.fundEditForm.strfunAmount.focus();
				return false;
			}
			if(s[0].length > 7) {
				alert('<bean:message key="fund.budgetamount"/>');
				document.fundEditForm.strfunAmount.focus();
				return false;
			}
	}
 
}
 
function digitsalone(txtCtrl)
{
	NumberValidateCheck(eval(txtCtrl));
 
}
 
function cancelProcess()
{
	var frmName = document.fundEditForm;
	cmbIndex = getComboIndex(frmName,'funSponsorid.spoId');
	cmbIndex1 = getComboIndex(frmName,'funPaymentmodeid.pmtId');
	if ((frmName.funPaymentdate.value != "") || (frmName.strfunAmount.value != "") || 
	(frmName.elements[cmbIndex].value != 0) || (frmName.elements[cmbIndex1].value != 0) || 
	(frmName.funPurpose.value != "Select")) 
	{
		if(confirm('<bean:message key="cancelDetails"/>')) {
			window.location='/SITE/listFund.do?method=listFund';
		}
	}
	else{
		window.location='/SITE/listFund.do?method=listFund';
	}
}								
function getComboIndex(frmname,ctrlname) { 
	for (var i=0; i < frmname.elements.length; i++){
	   if (frmname.elements[i].name == ctrlname){
		return i;
	   }
	}
}
function getPurpose()
{
	var cmbIndex=0;
	var frm = window.opener.document.fundEditForm;  
	cmbIndex = getComboIndex(frm,'funSponsorid.spoId');
	frm.elements[cmbIndex].value
	var comboIndexId = frm.elements[cmbIndex].value;	
	
	FundEditAction.getSponsorshipById(comboIndexId, function(price1) { 
	if(price1 == "Child Individual")
		frm.funPurpose.value="Individual Sponsorship";
	if(price1 == "Child Collective")
		frm.funPurpose.value="Collective Sponsorship"; 
	if(price1 == "Donation")
		frm.funPurpose.value="Donation";
	 });
 
}
function change() {
		//document.fundEditForm.elements["do"].value="getSubProjectCombo";
		//document.fundEditForm.submit();
		
		var cboName = "funProjectid.sproId";
		var projectId = document.fundEditForm.projectId.value;
		DWRUtil.removeAllOptions(cboName);
	var comboBox = document.getElementById(cboName);
	var oOption = document.createElement("OPTION"); 
		
		//Default Option Selected 
	oOption.value = "0";
	oOption.text = "Select";
	oOption.selected = true;
	addBIOption(comboBox,oOption);
//	comboBox.add(oOption);
	FundEditAction.getSubProjectCombo(projectId, function (subprojects) {
		if(subprojects.length !=0 )
		{
			$('noSubproject').style.visibility="hidden";
			for (var i = 0; i < subprojects.length; i++) {
				var subproject = subprojects[i];
				var oOption = document.createElement("OPTION");
				oOption.value = subprojects[i].sproId;
				oOption.text = subprojects[i].sproName;
				addBIOption(comboBox,oOption);
			//comboBox.add(oOption);
			}
		}
		else
		{
			$('noSubproject').style.visibility="visible";
		}
	});
}
 
function addBIOption(selectElement,newOption)
 {
	try 
	{
		selectElement.add(newOption,null);
	}	
	catch (e)
	{
		selectElement.add(newOption);
	}
}
</script>
 
<fieldset class="fieldset">  
							<legend><bean:message key="fund.details"/></legend>
	  <table width="100%" border="0" cellpadding="1" class="tabletext1" id="sponsorsHeader">
	  <tr>
		  <td width="88%" height="26" ><b><bean:message key="sponsor.search"/> </b>
		    <input name="spBeginWith" type="text" class="textbox" id="spBeginWith" onKeyUp="checkValue(this.value);" size="30" maxlength="100"></td>
			
	      <td width="12%" ><a href="javascript:self.close()">X</a> </td>
	  </tr>
	  <tr><td height="30" colspan="2" class="formdescription">  
	     (Please type the search text in the Text box, the results will be shown in the below)
		
		 </td>
	    </tr>		
	</table>
</fieldset>
 
  <table width="100%" border="0" cellpadding="1" id="sponsorsBody"> 
	  <tbody id="sponsorsTable" >
		  <tr id="pattern" style="background-color: rgb(255, 251, 249) ;display:none;" onMouseOver="this.style.backgroundColor = '#F5F4E9'" onMouseOut="this.style.backgroundColor =''" align="left" bgcolor="#fffbf9" valign="top" >
		  <td width="89%" class="tabletext1">&nbsp;<a href="#" onClick="setSelectedValue('funSponsorid.spoId',this.id.substring(6));getPurpose();" id="spName" class="topmenublue"></a></td>			
		  </tr>
    </tbody>
	</table>	
	
 
</body>
</html>

Open in new window

0
 
ss_pCommented:
did u try to do the DWR test to see if there are DWR calls beng handled

try

http://localhost:postno/app/dwr

you should be able to see your registered beans.

if not DWR is not loaded properly

let us know
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.