Reputation: 13328
I've got an applet that runs fine in firefox, however in ie8 (and ie7 I think), the javascript doesn't seem to be able to access the applets methods.
in the js debugger -
scanApplet.addUploadParameter
gives me a java exception -
java.lang.NoSuchFieldException: addUploadParameter in class: co.altcom.cache.scanner.CacheScan
The (jquery) code I'm actually trying to run is
$('input, select').each(function () {
scanApplet.addUploadParameter(this.name, this.value);
});
Which is throwing the following java exception -
java.lang.NullPointerException
I don't really know where to start with this..
Upvotes: 2
Views: 670
Reputation: 13328
I didn't include it in my question but I was creating the scanApplet variable using jquery -
var scanApplet = $('#scanApplet')[0]
It looks like it was the scanApplet
variable that was the problem. The following code fixes the problem.
$('input, select').each(function () {
var el_name = $(this).prop('name');
var el_value = $(this).val();
if (Browser.Version() < 8) {
scanApplet.addUploadParameter(el_name, el_value);
} else {
$('#scanApplet')[0].addUploadParameter(el_name, el_value);
}
});
I've no idea why ie7 allows me to reference the applet like this, there's no assignment to scanApplet in my code - I guess it's something to do with the way java's deployJava.js deals with ie, but I never found any documentation about it. I'm deploying the applet using the following -
var attributes = {id: 'scanApplet', code: "{{ jar_path }}", width:1, height:1} ;
var parameters = {jnlp_href: "{{ jnlp_path }}"} ;
deployJava.runApplet(attributes, parameters, '1.6');
Neither have I got any idea what broke my code, I think I've changed the versions of jquery I've been using but I tried quickly swapping out 1.6.1 for 1.4.2 and that didn't fix my orginal code.
Anyway referencing the applet by it's id seems to fix my issues in ie7.
Upvotes: 0
Reputation: 63759
Within the each
you should use the this
keyword wrapped in the jQuery function. In addition, for name you can use the prop
function, and for value there's the val()
function. So the jQuery would be:
$('input, select').each(function () {
scanApplet.addUploadParameter($(this).prop('name'), $(this).val());
});
That should fix the JavaScript bit. Without more info I can't tell if it fixes all your problems, and whether it fixes the Java error, so get back to us with more info if you still need more help after this.
Edit
In the comments it's mentioned IE7 still give problems. You should be debugging the call in IE7 then to see which bit of the code is giving you trouble. A quick, oldskool and very dirty way would be to just log or alert things to see where the problem is. E.g.:
// scanApplet.addUploadParameter($(this).prop('name'), $(this).val());
alert(scanApplet);
alert(scanApplet.addUploadParameter);
alert($(this).prop('name'));
// etc etc
Upvotes: 2