• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refresh a table in Struts

 
sapna dhamone
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have used table-tag to draw a table in my application using struts framework. I am displaying all the records in the table ,using an iterator . I want to refresh only this table after certain interval (as I have multiple tables in this particular JSP i just want one table to be refershed).
i.e., after refreshing the table the records must be present in the form, as I want to pass the form values to the next request.



The table code is as below.



<table>

<logic:iterate id="running" name="vehiclesRunning">

<tr>

<td width="16%"><bean:message key="asl.vehicleRegNo"/></td>

<td width="11%"><bean:message key="asl.date"/></td>

<?tr>

</logic:iterate>

</table>



I was able to refresh a textbox using Ajax, but unable to refresh a table content.

Can someone help me how to refresh a table either using Ajax/datagrid.


Thanks in Advance
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fear refreshing a textbox is perhaps one of the simplest things you can achieve using AJAX. If I'm correct you are dealing with String values when refreshing the textbox value.
However, in case of a table/data-grid, you would have to employ a more complex form of communication, namely, the XML. By 'complex' I am in no way referring to the difficulty of actually implementing it, I simply meant XML is more complex as compared to a String.
What you'll need to do is: Create an XML string at your server capturing the new data to be populated in the table. Once the server sends back the string, you'll have to write a JavaScript snippet, which will parse this XML and create a new table HTML structure. Thereof, substitute the previous table's HTML by this new HTML. For this, place the HTML code of the table within a <DIV> and then you set the 'innerHTML' property of this DIV.
 
sindhu sheela
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to create a xml string in the server side?can you please let me know.

Thank you in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sindhu CR",
Please check your private messages regarding an important administrative matter.
-Ben
 
Kanchan Singh
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bellow is the code to create xml file on server side.
I hope this helps you.

response.setContentType("text/xml");
PrintWriter out=response.getWriter();
out.write("<?xml version='1.0' encoding='ISO-8859-1'?>");
out.write("<main>");
out.write("<?xml version='1.0' encoding='ISO-8859-1'?>");
out.write("<main>");
out.write("<company>");
// out.write("<link>"+""+"</link>");
out.write("<compname>"+"GE1"+ "</compname>");
out.write("<contname>"+"Kanchan"+"</contname>");
out.write("<address>"+"BN"+"</address>");
out.write("<city>"+"Pune"+"</city>");
out.write("</company>");
out.write("<company>");
out.write("<compname>"+"GE2"+ "</compname>");
out.write("<contname>"+"Kanchan"+"</contname>");
out.write("<address>"+"BN"+"</address>");
out.write("<city>"+"Pune"+"</city>");
out.write("</company>");

out.write("<SupplierID>");
out.write("<id>"+"1"+ "</id>");
out.write("<id>"+"2"+ "</id>");
out.write("</SupplierID>");

out.write("</main>");

out.flush();
out.close();
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic