• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

JSP Ajax append html table problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67734
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a JSP issue. Moved to the HTML/Javascript forum.
 
Bear Bibeault
Sheriff
Posts: 67734
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic