aspose file tools*
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to refresh a table in Struts" Watch "How to refresh a table in Struts" New topic
Author

How to refresh a table in Struts

sapna dhamone
Greenhorn

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.



<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

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
Greenhorn

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
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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


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.

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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to refresh a table in Struts