Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

how does this code work

 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67641
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
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: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67641
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
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: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic