Skip to main content

Ajax call response in struts. Response not reflected in jsp.



I am calling a struts action on using an ajax call. In it i am changing the values of some properties of the action class. The values are set properly but i am not able to reflect the changes in the jsp.





The jsp code is as follows.







<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



<%@ taglib prefix="s" uri="/struts-tags"%>

<html>

<head>

function findindex1()

{

var temp=document.getElementById("country").value;

if(window.ActiveXObject){ request = new ActiveXObject("Microsoft.XMLHTTP"); }

else if(window.XMLHttpRequest){ request = new XMLHttpRequest(); } request.onreadystatechange = showResult;

request.open("POST",'temp.action?index='+temp,true);

request.send(null);

}

function showResult(){

if(request.readyState == 4){

document.getElementById("city").flush();

}

}

</head>

<body onload="fill()">

<s:form method="post" action="product.action" name="product" theme="simple">

<table id="table">

<tr><td>Country</td><td><s:select id="country" name="country.countryId" list="countryList" listKey="countryId"

listValue="name" onchange="findindex1()" ></s:select></td></tr>

<tr>

<td>City</td>

<td><s:select id="city" name="city.id" list="cities" listKey="id"

listValue="name" headerKey="city.id" ></s:select></td>

</tr>



<tr>

<td><s:submit id="search" name="submit" value="Search"></s:submit></td>

<td><s:submit name="submit" value="Create"></s:submit>

</td>

</tr>

</table>

</s:form>

</body>

</html>







The action class method is as follows ...







public String temp(){

String[] id=(String[])getParameters().get("index"); //get the country index

index=Integer.parseInt(id[0]);

cities=(ArrayList<City>)productCreateService.selectCities(Integer.parseInt(id[0])); //populate corresponding cities



return SUCCESS;

}







Up till this it is working . The call to this method is executed and the cities(which represent the dropdown list) is populated properly. All now i want is to reflect this updated cities in jsp. I cant seem to do that.





Can anyone help .... ???





Note: I have used the flush function for no particular purpose but just for hit and trial.





P.S. : I know the code is a little vague. So if any more information is needed please let me know ...





Thanks


Comments

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.