4

I am trying to pass a selected value from HTML drop-down to an Applet method, using setter method in the Applet. But every time the Javascript is invoked it shows "object doesn't support this property or method" as an exception.

My javascript code :

function showSelected(value){
 alert("the value given from"+value);
 var diseasename=value;
 alert(diseasename);
 document.decisiontreeapplet.setDieasename(diseasename);
 alert("i am after value set ");
}

My applet code :

package com.vaannila.utility;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import prefuse.util.ui.JPrefuseApplet;
public class dynamicTreeApplet extends JPrefuseApplet {
 private static final long serialVersionUID = 1L;
 public static int i = 1;
 public String dieasenameencode;
 //System.out.println("asjdjkhcd"+dieasenameencode);
 public void init() {
 System.out.println("asjdjkhcd"+dieasenameencode);
 System.out.println("the value of i is " + i);
 URL url = null;
 //String ashu=this.getParameter("dieasenmae");
 //System.out.println("the value of the dieases is "+ashu);
 //Here dieasesname is important to make the page refresh happen 
 //String dencode = dieasenameencode.trim();
 try {
 //String dieasename = URLEncoder.encode(dencode, "UTF-8");
 // i want this piece of the code to be called 
 url = new URL("http://localhost:8080/docRuleToolProtocol/appletRefreshAction.do?dieasename="+dieasenameencode);
 URLConnection con = url.openConnection();
 con.setDoOutput(true);
 con.setDoInput(true);
 con.setUseCaches(false);
 InputStream ois = con.getInputStream();
 this.setContentPane(dynamicView.demo(ois, "name"));
 ois.close();
 } catch (MalformedURLException e) {
 e.printStackTrace();
 } catch (FileNotFoundException f) {
 f.printStackTrace();
 } catch (IOException io) {
 io.printStackTrace();
 }
 ++i;
 }
 public void setDieasename(String message){
 System.out.println("atleast i am here and call is made ");
 this.dieasenameencode=message;
 System.out.println("the final value of the dieasenmae"+dieasenameencode);
 }
}

My appletdeployment code :

<applet id="decisiontreeapplet" code="com.vaannila.utility.dynamicTreeApplet.class" archive="./appletjars/dynamictree.jar, ./appletjars/prefuse.jar" width ="1000" height="500" > 
</applet>
Perception
80.8k19 gold badges190 silver badges197 bronze badges
asked Sep 2, 2011 at 2:14
2
  • possible duplicate of value passing in java applet Commented Sep 2, 2011 at 2:22
  • @Nate That does look very familiar! OP please don't repost questions. Commented Sep 2, 2011 at 4:57

4 Answers 4

7

Change..

document.decisiontreeapplet

..to..

document.getElementById('decisiontreeapplet')

..and it will most likely work.

E.G.

HTML

<html>
<body>
<script type='text/javascript'>
function callApplet() {
 msg = document.getElementById('input').value;
 applet = document.getElementById('output');
 applet.setMessage(msg);
}
</script>
<input id='input' type='text' size=20 onchange='callApplet()'>
<br>
<applet
 id='output'
 code='CallApplet'
 width=120
 height=20>
</applet>
</body>
</html>

Java

import javax.swing.*;
public class CallApplet extends JApplet {
 JTextField output;
 public void init() {
 output = new JTextField(20);
 add(output);
 validate();
 }
 public void setMessage(String message) {
 output.setText(message);
 }
}

Please also consider posting a short complete example next time. Note that the number of lines in the two sources shown above, is shorter that your e.g. applet, and it took me longer to prepare the source so I could check my answer.

answered Sep 2, 2011 at 2:44
Sign up to request clarification or add additional context in comments.

3 Comments

hi andrew its not working even now everytime i try to invoke setmethod in my applet object its saying object doesnot support this method ..is their any way to debug this .
"its not working" The example shown above works for me in FF. "is their any way to debug this(?)" If using FF, open the Error Console (Ctrl+Shift+J).
was a cache problem .it worked for me as well :) thanks a ton
1

Try changing the id parameter in your applet tag to name instead.

<applet name="decisiontreeapplet" ...>
</applet>
answered Sep 2, 2011 at 2:26

Comments

-1
answered Sep 2, 2011 at 2:18

Comments

-1

I think the <applet> tag is obsolete and <object> tag shoudl be used instead. I recall there was some boolean param named scriptable in the object tag.

Why you do not use deployment toolkit ? It would save you a lot of trying - see http://rostislav-matl.blogspot.com/2011/10/java-applets-building-with-maven.html for more info.

answered Oct 12, 2011 at 12:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.