File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes How to refresh a table in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to refresh a table in Struts" Watch "How to refresh a table in Struts" New topic

How to refresh a table in Struts

sapna dhamone

Joined: Apr 17, 2008
Posts: 5
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.


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


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

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




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

Joined: Feb 22, 2005
Posts: 261
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

Joined: May 20, 2008
Posts: 26
How to create a xml string in the server side?can you please let me know.

Thank you in advance.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"Sindhu CR",
Please check your private messages regarding an important administrative matter.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kanchan Singh
Ranch Hand

Joined: Dec 27, 2007
Posts: 38
Bellow is the code to create xml file on server side.
I hope this helps you.

PrintWriter out=response.getWriter();
out.write("<?xml version='1.0' encoding='ISO-8859-1'?>");
out.write("<?xml version='1.0' encoding='ISO-8859-1'?>");
// out.write("<link>"+""+"</link>");
out.write("<compname>"+"GE1"+ "</compname>");
out.write("<compname>"+"GE2"+ "</compname>");

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


It is sorta covered in the JavaRanch Style Guide.
subject: How to refresh a table in Struts
It's not a secret anymore!