FIX: Event Scripting Breaks for Multiple Java Beans on the Same Web Page (242014)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1

This article was previously published under Q242014

SYMPTOMS

When you script Java bean events in Internet Explorer, some events may not be fired if more than one bean exists on the same Web page.

CAUSE

This problem is caused by the browser's caching of type information for Java bean objects that are hosted on a Web page.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Internet Explorer 5.5.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new .htm file named Page1.htm, and paste the following code:Page1.htm
    <html>
    <head>
    <script language="JavaScript">
    function generateAppletOneEvent()
    {
    	alert("Script event function called for applet one.");
    	window.document.EBAppletOne.generateEvent();
    }
    
    function generateAppletTwoEvent()
    {
    	alert("Script event function called for applet two.");	
    	window.document.EBAppletTwo.generateEvent();
    }
    </script>
    <title>Multiple Applet Event Bug Test</title>
    </head>
    <body>
    <table border="1" width="100%">
      <tr>
        <td width="50%">
          <applet 
            code="EBAppletOne.class" 
            name="EBAppletOne" 
            width="320" 
            height="200" 
            VIEWASTEXT>
              <param name="FiresScriptEvents" value="true">
          </applet>
          <input 
            type="button" 
            value="Generate Applet One Event" 
            onclick="generateAppletOneEvent()">
        </td>
        <td width="50%">
          <applet 
            code="EBAppletTwo.class" 
            name="EBAppletTwo" 
            width="320" 
            height="200" 
            VIEWASTEXT>
              <param name="FiresScriptEvents" value="true">
          </applet>
          <input 
            type="button" 
            value="Generate Applet Two Event" 
            onclick="generateAppletTwoEvent()">
        </td>
      </tr>
    </table>
    <script 
      language="JavaScript" 
      for="EBAppletOne" 
      event="onEBAppletOneEvent(source)">
        alert(source + " fired an event.");
    </script>
    <script 
      language="JavaScript" 
      for="EBAppletTwo" 
      event="onEBAppletTwoEvent(source)">
        alert(source + " fired an event.");
    </script>
    </body>
    </html>
    					
  2. Compile the following Java source files:EBAppletOne.java
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    
    public class EBAppletOne extends Applet { 
      private Vector listeners;
      
      public void init() { 
        Label l = new Label();
        l.setAlignment(Label.CENTER);
        l.setText("This is applet one.");
        add(l);
      }
      
      public void generateEvent() { 
        try { 
          if (listeners == null)
            return;
          Enumeration e = listeners.elements();
          while (e.hasMoreElements()) { 
            EventObject eo = new EventObject(this);
            ((EBAppletOneListener)e.nextElement()).onEBAppletOneEvent(eo);
            System.out.println("Event fired from applet one:  "+eo.toString());
          }
        }
        catch (Exception ex) { 
          ex.printStackTrace();
        }
      }
    
      public void addEBAppletOneListener(EBAppletOneListener list) { 
        if (listeners == null)
          listeners = new Vector();
        listeners.addElement(list);
      }
      
      public void removeEBAppletOneListener(EBAppletOneListener list) { 
        if (listeners != null)
          listeners.removeElement(list);
      }
    }
    					
    EBAppletTwo.java
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    
    public class EBAppletTwo extends Applet { 
      private Vector listeners;
      
      public void init() { 
        Label l = new Label();
        l.setAlignment(Label.CENTER);
        l.setText("This is applet two.");
        add(l);
      }
    
      public void generateEvent() { 
        try { 
          if (listeners == null)
            return;
          Enumeration e = listeners.elements();
          while (e.hasMoreElements()) { 
            EventObject eo = new EventObject(this);
            ((EBAppletTwoListener)e.nextElement()).onEBAppletTwoEvent(eo);
            System.out.println("Event fired from applet two:  "+ eo.toString());	
          }
        }
        catch (Exception ex) { 
          ex.printStackTrace();
        }
      }
    
      public void addEBAppletTwoListener(EBAppletTwoListener list) { 
        if (listeners == null)
          listeners = new Vector();
        listeners.addElement(list);
      }
      
      public void removeEBAppletTwoListener(EBAppletTwoListener list) { 
        if (listeners != null)
          listeners.removeElement(list);
      }
    
    }
    EBAppletOneListener.java
    import java.util.*;
    
    public interface EBAppletOneListener extends EventListener
    {
    	public void onEBAppletOneEvent(EventObject e);
    }
    					
    EBAppletTwoListener.java
    import java.util.*;
    
    public interface EBAppletTwoListener extends EventListener
    {
    	public void onEBAppletTwoEvent(EventObject e);
    }
    					
  3. Copy the resultant .class files to the same folder as the Page1.htm file.

    NOTE: These files do not need to be on a Web server to demonstrate the problem.
  4. In Internet Explorer, open Page1.htm.
  5. Click the applet buttons to generate bean events. Only one of the applets or beans fires events to the Web page script handlers.

REFERENCES

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbBug kbfix kbie550fix kbJava KB242014 kbAudDeveloper