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

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex