Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

how does this code work  RSS feed

 
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found some code on SO that does what I want, but I don't understand how it works. Background: I have an iframe which will display a chart (JFreeChart) generated by a servlet. The user enters a date range which goes to another servlet which gets the dataset and puts it in the session. The chart generator grabs that dataset and creates the chart. I needed to refresh the iframe so it would build a new chart when the parameters are entered or new parameters are entered.

This may not be the best way to do things, but after two days of struggling with JFreeChart, this is what I came up with, based on the examples in their developer guide.

The first solution suggested was this:

In other words, setting the src attribute to itself to force a refresh. This didn't work for me. This does work:

But I don't understand how it works. If I leave out the "i" parameter, it doesn't work. So what is "i" and where does "val" get a value from?
 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, that's a weird one and not one of the browser vagaries that I've seen. You can set a breakpoint in the function to see what's bing passed to it (if anything) as the 2nd param.

And here's where I offer an alternative: nothing made me happier than when I stopped trying to do charting on the server and moved it to the client. You may find that switching to a client-side charting package such as HighCharts causes you to pull out less hair.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called from the success function of an Ajax call. I tested it and "i" is zero (a default value?), and val is the src url of the iframe, but I don't know how it's getting that.

It's a weird one alright. It works, but I hate not knowing why it works.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

J. Kevin Robbins wrote:It's called from the success function of an Ajax call.



There is no Ajax call!


Read the documentation for http://api.jquery.com/attr/#attr-attributeName-function
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric beat me to it.

It still doesn't solve the issue of why the first form didn't work for you, but I prefer the 2nd form in any case because it does not rely upon repetition of the selector (a vector for introducing errors).

[Aside: I'd still recommend looking into client-side charting. There are lots of advantages, including interactivity, simplification if the code, and elimination of the iframe.]
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eric Pascarello wrote:
There is no Ajax call!


Sorry, I was trying to keep the code to a minimum since it was that one line that puzzled me.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
[Aside: I'd still recommend looking into client-side charting. There are lots of advantages, including interactivity, simplification if the code, and elimination of the iframe.]


I never heard of HighCharts. I'm going to look at it. Thanks for that tip.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!