Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Appending a Blog Summary Feed to JSP page  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank binary heaven for this site! I'm trying to oil my rusty Java wheels again, and could really use some direction. The objective I am trying to achieve is to fetch Blog posts from Blogger, and my code is getting hung up somewhere.

Setup: JSON/AJAX in a JS page; called in JSP page.

This is the code to pull blog summaries for each posting:




And this is the code to call the function in the JSP Page:


Any thoughts are greatly appreciated. I think my index check at the end may be set up incorrectly, but then again, this whole design is probably outdated....
 
Sheriff
Posts: 67258
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Little Butterfly wrote:I'm trying to oil my rusty Java wheels again...



First, let's get some obvious things out of the way. This has nothing to do with Java, or with JSP. JavaScript is executed on the client, after the JSP has been used as a template on the server to format the vanilla HTML page to send to the browser. All JSP-ness is long gone from the page.

What I would recommend at this point is to open up the browser's debugger, set a breakpoint at the function, and step through it to see where what it is doing deviates from your expectations.

Little Butterfly wrote:And this is the code to call the function in the JSP Page...



I'm not seeing any calls to the function in your code. Are you sure it's being called in the first place?


 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the clarification....

Javascript.

The portion I should have included to call the function:
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And thank you for the welcome and suggestions also... I am working through the code again now, in Eclipse.
 
Bear Bibeault
Sheriff
Posts: 67258
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you verified that the function is even being invoked? A breakpoint or even logging statement at the beginning of the function would tell you so.

I haven't done much playing with CORS yet, but I would assume that the callback=mycallback parameter would name your callback, which is not named mycallback, but I'm just guessing.
 
Bear Bibeault
Sheriff
Posts: 67258
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few more observations:

This line does not make sense:
$.support.cors is intended to tell you whether the browser supports CORS or not. Changing its value to true has no effect except to override the actual setting if false.

You are obviously using jQuery for much of the code, yet rather than using jQuery DOM manipulation to create new elements, you are building up HTML in strings:That's, ummm, well, odd and not a great way to do it.
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good chilly day! Hibernating in a 2ft' snow blizzard , but I'm still at it! Thank you for pointing out that very sore spot, a very silly error to make. #green

I appreciate all the observations, helpful hints, etc, and have been using them to improve on my code over the weekend.

A bit of context:
Unfortunately, I'm starting from another developers code, and a lot of this doesn't make sense. I'm not very experienced, but I know that it is bad practice to have <%scriptlets%> governing a majority of a JSP. The end product is being imported into SAP Portal as a web application. So unfortunately, some of this backward coding may be necessary...
I've been taking pieces of code bit by bit and trying to improve.

I've purchased a copy of your book, "JQuery in Action", and soon also "Secrets of the JavaScript Ninja."
Thank you for your contributions to the IT world!

I'm ready to resume the fun:
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my (hopefully) improved code. I took the HTML strings and created(AN ATTEMPT!) DOM elements for the 'items' processing*. 'items1'& 'items2' are utilized in proceeding elements to complete appending tasks:



I still have not been able to get a break-point in to do the browser debugging. Any additional constructive criticism? I appreciate your time and expertise!

*Reference I used for the DOM elements: http://learn.jquery.com/using-jquery-core/manipulating-elements/.
 
Bear Bibeault
Sheriff
Posts: 67258
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What problems are you having using the debugger? It really is the best way to debug JavaScript code. Otherwise, there's just a lot of guessing.

While each browser has its own set of tools, I find the Chrome debugger the most intuitive and useful.

(Interestingly enough, I don't like Chrome as a browser and use Safari for my day-to-day browsing, using Chrome only for development.)

(P.S. 21 degrees in Austin this morning. While I know a lot of the US is colder, and under snow, it's very unusual for this far south! )
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None of my programs are allowing me to add breakpoints to review the functions in the system... Though the real issue may be I don't know how to set this up properly:



This is what I see when I try to click events in the console. Do I need actual document. statements for this to work?


(P.S. All of these recent weather systems are unnatural, there's been a total of 20 inches in Missouri so far, lowest temp of -20F, and it's snowing again today. Yes, 21 is terribly cold for the south! Egypt got snow too, last time was over 200 years ago...Hmm.)


 
author
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To set a breakpoint go into the sources tab, then expand the tree to find your source file.
 
Bear Bibeault
Sheriff
Posts: 67258
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Chrome debugger:


view full-sized

[Edit: Rob beat me to it]
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for the reply!!
It is just as I suspected, this is far from set up properly. And I believe this is the reason why I had everything chunked up in an html file initially. So my javascript needs to be re-constructed to be displayed...


 
Bear Bibeault
Sheriff
Posts: 67258
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh? Not getting what you are saying. (and the screenshot is too indistinct to see anything useful)
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I click on the Sources and expand the tree to open my source file, no code is displayed in the window...
 
Rob Crowther
author
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the JavaScript file you have loaded doesn't have any sources. Go back to your HTML page, then look it its sources.
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your assistance..... My recent progress awards only 7 feet on my neck, instead of 8. haha.

After spending yesterday I'm doing a bit better. The Web Inspector helps a bit, and by a bit I probably mean a lot.

I've completely reconstructed my code (again!) and now trying to get it to display properly in my application project:



Looks like my programming logic is slightly improving already! NOW. The issue that I'm having is getting this project to run in a package I am creating with SAP's version of Eclipse, described in following post:
 
Rob Crowther
author
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't do document.write, that will replace the currently loaded document. You should grab an element with document.getElementById and then append your new content to it, or use jQuery and appendTo as you were doing originally. Also, replacing newlines with spaces is redundant because that happens anyway when you add the text to an HTML document.
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main piece project is a JavaScript page that references several external scripts, including the JSON callback to call the function fetchBlogPost (renamed mycallback, hoping that it would give me fresh perspective.)
The main js initializes project and fetches the necessary data as well as the blog post function:



During functions processing, fetchBlogPost is instantiated, and its results should be returned to a div id "latestBlogEntry" that is also specified in the main JSP.

Here's the Initializing statement, aka "ON" switch:


The main JSP has the div setup to receive the play:


with the script call at the end.




I really can't figure out how to test this, as html is needed to use the inspector. Any helpful hints or direction from you kind hearts?? I have the package available, so I can give more code or supply it if necessary...
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... That's probably why none of the feed is showing up if I'm overwriting. Thank you Rob, just now seeing your reply!

Let me try this first, while I'm making sure all of my divs are closed properly.
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And in response to replacing line breaks... there is one particular section that I've gotten hung up on in my previous builds, maybe you can shed some light there too? The best result I've gotten firing this code up successfully is one sentence. After that sentence in the API, you can see a bunch of styling and line breaks, and this particular case may need something extra:



Is there a better way to try and get the rest of this post to feed through?
 
Vanessa Rhodes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to update this post with my progress, in case anyone look through this in the future.

All document.write() tags have been replaced with a .push() into the HTML element for the blog. Yes the ugly concatenation is necessary for this project, because the Portal environment seems to hang up on passing my json object via ajax, I may be wrong here but I can get this code to run 99% as expected in the enterprise software:





The last piece is the date format. I am trying to pull a full date with weekdays, and in IE the object is returning undefined, NaN NaN:


Is there something I can add to this code so that IE would recogize this without the T character? Another solution I found that I may integrate is adding something like this:




Any additional thought are greatly appreciated. Having this site and a few trusty books as references has helped me to think outside the box.
 
Danger, 10,000 volts, very electic .... tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!