File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JSP Ajax append html table problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JSP Ajax append html table problem" Watch "JSP Ajax append html table problem" New topic
Author

JSP Ajax append html table problem

John Seals
Greenhorn

Joined: Dec 30, 2008
Posts: 5
Greetings Gurus:

I am appending data, via Jquery and AJAX from an external JSP to an existing JSP when a user clicks on a link. For example:

1. This page (page1.jsp) has three HTML tables on it that are populated with data via a servlet/database (servlet number 1) when the page loads. (I load records based on rownum >=0 <= 10 for instance)
2. Then the user clicks a link on this page (page1.jsp) which calls another servlet (servlet number 2) that populates another jsp (page2.jsp). (I load records based on rownum >=10 <= 11 for instance)
3. Using Jquery/Ajax I then append the contents of page2.jsp into one of the tables on page1.jsp.

Kind of confusing I know but it works fine. But my problem is this: How do I tell the original page (page1.jsp) when there is no more data to be appended? For example the user clicks the link on page one and never knows that there returning recordset is empty. Ideally I would like to hide the link on page1.jsp that allows them to add more records when the recordset is empty. I can tell on the page2.jsp and servlet number 2 that there are no more records but how do I pass this info back to page1.jsp?

I know this might be a little confusing but I have not been able to figure this one out.

Any help would be greatly appreciated!
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Upon first load or the link clicking, also check if there are still more records to fetch (maybe in a separate ajax request), and then hide or display the link accordingly.

Also, this post belongs to the Ajax forum.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Not a JSP issue. Moved to the HTML/Javascript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Sounds to me as if you can just test the size of the response text in your jQuery success handler, and if empty, hide the link.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Bear Bibeault wrote:Sounds to me as if you can just test the size of the response text in your jQuery success handler, and if empty, hide the link.


I think he wanted to check in advance if the there are more results to come and hide the link accordingly, so he would need to send the request even without somebody clicking the link.
Maybe it's faster to run a separate request that just gets the result size as opposed to running the full request and getting the complete result if you only need the size.
John Seals
Greenhorn

Joined: Dec 30, 2008
Posts: 5
Thanks to everyone for the quick response. I apologize for putting this in the wrong location initially. These replies have all got me pointed in the right direction. I think I will utilize the method in the Jquery success handler as that makes the most sense to me at this time.

All the best!
Trilochan Bharadwaj
Ranch Hand

Joined: Feb 02, 2009
Posts: 100
John,

Did you get what Sebastian recommended? From what I could understand, a count request first hand sounds better to me, rather than getting the whole thing on client side, I can't say which one's more performance oriented though, personally I'd keep all those things on server bay and have min. data to deal with on client end.

Trilochan.


Trilochan Bharadwaj
Ranch Hand

Joined: Feb 02, 2009
Posts: 100
OK, not being a JQuery expert , I'll leave the js code to you, but you could do this:
1.) allow the processing to happen on server end, and server sends out a JSON response.
2.) have a marker in JSON to see if the data if the links to be displayed.
3.) finally display the results (present in JSON array).

Trilochan
John Seals
Greenhorn

Joined: Dec 30, 2008
Posts: 5
Trilochan:

Thanks for following up. Basically what I did was check the results on the client end. If they are empty I no longer append data. The problem with the page is it has 6(!) different tables on it with each querying a different database. (yowsa!) The client wants one button to update/paginate all of them. They also then want the tables with no new data available indicate that there are no more new records. I don't think this is possible for multiple tables. I can easily hide the update link with css for each of the queries but trying to do it for all requires too many round trips to the db I think.

So I am going to provide links for updating each of the tables. And when there is no more data hide those particular links.

Thanks again for yours, and everyone else's, assistance!

John S.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Ajax append html table problem