• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Ajax - load a particular part of JSP

 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a JSP that fetches data from different queries. In this jsp i have section , in which if i select a particular row then i need to fire only one query and to load a portion in jsp.
In this case it is not desired to load whole page. so i just wanted to load a selected portion that is a <table></table>
I heard JSON/JQUERY can help me in this dilemma.
But after searching through sites, i could not reach to any solution.
Can someone help me in solving this issue.

Thanks a lot.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you only need to load a small part of a requested page, put that part of the page in its own JSP. You can always include it on pages where you need it along side everything else but then it will be available when that is all you need.
 
Marshal
Posts: 67286
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Gregg points out, you can't just pick a part of another page to load. You must take the entire response. But you can define that response to be anything you want -- it doesn't have to be a full HTML page. It's quite common in Ajax-enabled applications to load page fragments piece-meal in order to end up with a complete page in the browser.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change a field on a page and refresh another part of the page...sounds like a very typical application of Ajax. I take it that you are pretty new to Ajax technology. The core part of Ajax technology is pretty straight forward but the learning curve can be a bit steep because it brings in a lot of other technologies such as CSS, JavaScript, DOM manipulation and JavaScript frameworks (like jQuery).

I might be the only one using it, but I adopted AjaxAnywhere for my project (http://ajaxanywhere.sourceforge.net/). AjaxAnywhere can be a good fit for project where you already have a working application and you want to use Ajax to limit full page refreshes.

- Brent
 
Bear Bibeault
Marshal
Posts: 67286
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Brent Sterling:
Change a field on a page and refresh another part of the page...t

I believe that the problem nuance -- unless both Gregg and I are misconstruing something -- is that the OP isn't just look to replace part of a page, but to grab just part of another JSP page.
[ March 12, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the OP wants to do an initial page load. Then when a particular item on the page is selected (a table row I would guess) then the OP wants to load a new table with information from the DB via an AJAX request. I would use jqGrid to do this. It handles JSON data and can do this parent/child select/load scenario.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe we'd be better off waiting for the OP to respond before we start telling her what china pattern would best suit her dining room.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I vote for the Villeroy & Boch "Toscana" Dinnerware Collection...just fabulous! ;-)

- Brent
 
Bear Bibeault
Marshal
Posts: 67286
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too pissy! Fiestaware goes with everything!
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i somehow could not make clear my problem. I know AJAX can help me in fetching data. But problem is how to put that list (data) to refresh some part of jsp. Eg.


Now by using dwr for my AJAX i somehow manage to get the refreshed data list.But now i need to use this data list for refreshing jsp ( the code mentioned.)Please let me know how can i refresh this html table.

Thanks a lot to all.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know much about DWR. Maybe this article will help:

http://dev2dev.bea.com/pub/a/2005/08/ajax_introduction.html

You have to get to page two to see some DWR example code. The code is not building a table, but the same would apply. The example builds up the html using JavaScript code and then uses the innerHTML property. These days, direct DOM manipulation seems to be the cool thing, but if you are building a large table the innerHTML approach might be a good approach.

- Brent
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"These days, direct DOM manipulation seems to be the cool thing, but if you are building a large table the innerHTML approach might be a good approach."

That's an interesting comment, I would have claimed the exact opposite was true

There was a time when innerHTML didn't actually modify the DOM, at least in some browsers. So, doing:

someDiv.innerHTML = "<div id='myDiv' />";

...and then trying...

document.getElementById("myDiv")

...wouldn't work. At that time, direct DOM manipulation was the only way to go. But, in modern browsers, and I think going back at least a few versions, myDiv gets inserted into the DOM as expected, at which point innerHTML tends to be the way to go. There still may be instances where it's not sufficient, but I don't recall seeing such a case in any recent times.

I tend to see more use of innerHTML than DOM manipulation in the code I look at, that would have led me to think the opposite of your statement was true. Now, I may well be wrong, it certainly wouldn't be the first time (in the last 10 minutes even!), but it was an interesting difference I thought.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably those in the trenches doing this stuff would be better situated to provide a real answer (opinion) on the DOM versus innerHTML question. I have been more active in this forum lately because I have been doing research to figure out best practices for a project with a lot of JavaScript written by people that knew very little about JavaScript (including myself in that group).

95% of my Ajax experience is with AjaxAnywhere which hide most of the details (and uses innerHTML behind the scenes). If you are building html on the server side and returning that in your Ajax calls, then innerHTML seems like the only option. If you are using JSON or DWR then you have other options. Building up html string in JavaScript seems a little messy but so does a bunch of calls to createElement.

The book "Simply JavaScript" by Kevin Yank and Cameron Adams advocates direct DOM updates and that seems to be the preference that I get from other resources on the web. Here is a site that shows that using innerHTML has some definite performance advantages: http://www.quirksmode.org/dom/innerhtml.html

- Brent
 
Frank Zammetti
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd definitely say I'm "in the trenches", and that's completely discounting what I've done for my books, just considering what I do on the job. Granted I'm just one example, but I can't remember the last time I did DOM manipulation code in "real life", so to speak I suppose I could be the exception, but in speaking to various people over the past year I get the sense I'm not.
 
Bear Bibeault
Marshal
Posts: 67286
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Frank Zammetti:
but in speaking to various people over the past year I get the sense I'm not.

You are not.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
innerHTML is not the only way to add elements onto a page. You can also call Dom functions like appendChild.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!