Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4527955

Can't get HTMLInputElement from getElements() of HTMLFormElement in Netscape 4.7

XMLWordPrintable

    • x86
    • windows_nt



      Name: gm110360 Date: 11/15/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

      Methode getElements() in HTMLFormElement returns an HTMLCollection. The
      Elements in this Collection should be of type HTMLInputElement, but if the
      applet is running under netscapt, the elements are not of this type.

      I have an applet running in Netscape® Communicator 4.76.
      Html page:
      <HTML>
      <HEAD>
      <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252" />
      <TITLE>
      "HTML Test Page"
      </TITLE>
      </HEAD>
      <BODY>
      "Simple Appet test page"<BR>
      <!--"CONVERTED_APPLET"-->
      <!-- CONVERTER VERSION 1.3 -->

      <form>
        <input type="button" value="START">
        <input type="text" value="div-id2,bgcolor:red" name="field1">
      </form>

      <OBJECT>
      <EMBED type="application/x-java-applet;version=1.4" CODE
      = "SimpleApplet3.class" CODEBASE = "." NAME = "TestApplet"
      WIDTH = 0 HEIGHT = 0 ALIGN = top VSPACE = 0 HSPACE = 0 file = "../tree.xml"
      MAYSCRIPT="true" scriptable=false
      pluginspage="http://java.sun.com/products/plugin/1.4/plugin-
      install.html"><NOEMBED></COMMENT>

      </NOEMBED></EMBED>
      </OBJECT>

      <APPLET CODE = "SimpleApplet3.class" CODEBASE = "." WIDTH = 0 HEIGHT = 0 NAME
      = "SimpleApplet3" ALIGN = top VSPACE = 0 HSPACE = 0>

      </APPLET>
      <!--"END_CONVERTED_APPLET"-->

      </BODY>
      </HTML>

      Applet source:

      import java.awt.*;
      import java.awt.event.*;
      import java.applet.*;
      import javax.swing.*;
      import java.util.Observable;
      import java.util.Observer;

      import org.w3c.dom.* ;
      import org.w3c.dom.html.* ;
      import com.sun.java.browser.dom.*;

      public class SimpleApplet3 extends Applet
      {
        /** A reference of the object itself for inner class or anonymous class to
      reference */
        private Applet ja = this;

        public void init()
        {
          try
          {
            DOMService service = DOMService.getService(this);
            service.invokeAndWait( new DOMAction()
            {
              public Object run(DOMAccessor accessor)
              {
                HTMLDocument doc = (HTMLDocument) accessor.getDocument(ja);
                HTMLCollection forms = doc.getForms();
                HTMLCollection formElem = ((HTMLFormElement)forms.item(0)).getElements
      ();
                int l = formElem.getLength();
                for (int i = 0; i < l; i ++ )
                {
                  System.out.println("ele " + i + ": " + formElem.item(i).getClass
      ());
                  if (formElem.item(i) instanceof HTMLInputElement)
                  {
                    System.out.println("input : " + i);
                    HTMLInputElement input = ((HTMLInputElement)formElem.item(i));
                    if (input.getAttribute("type").equalsIgnoreCase("text"))
                    {
                      input.setValue("v");
                    }

                  }
                }
                return null;
              }
            });
          }
          catch (DOMAccessException dae)
          {
            dae.printStackTrace();
          }
          catch (DOMUnsupportedException use)
          {
            use.printStackTrace();
          }
        }
      }
      Expected printout is (Actualy this is the result when I running in Internet
      Explorer 5.5):
      ele 0: class sun.plugin.dom.html.HTMLInputElement
      input : 0
      ele 1: class sun.plugin.dom.html.HTMLInputElement
      input : 1


      Actually I got:
      ele 0: class sun.plugin.dom.html.HTMLElement
      ele 1: class sun.plugin.dom.html.HTMLElement

      In Netscape 6.2 the same applet throws a bunch of exceptions(which works in IE 5.5/6.0).
      Here is the output of java console

      Java(TM) Plug-in: Version 1.4.0
      Using JRE version 1.4.0-beta3 Java HotSpot(TM) Client VM
      User home directory = C:\Documents and Settings\Administrator
      Proxy Configuration: Browser Proxy Configuration


      ----------------------------------------------------
      c: clear console window
      f: finalize objects on finalization queue
      g: garbage collect
      h: display this help message
      l: dump classloader list
      m: print memory usage
      o: trigger logging
      p: reload proxy configuration
      q: hide console
      r: reload policy configuration
      s: dump system properties
      t: dump thread list
      x: clear classloader cache
      0-5: set trace level to <n>
      ----------------------------------------------------
      netscape.javascript.JSException
      at netscape.javascript.JSObject.getWindow(JSObject.java:149)
      at sun.plugin.dom.DOMServiceProvider.getDocument(DOMServiceProvider.java:57)
      at sun.plugin.dom.DOMAccessor.getDocument(DOMService.java:87)
      at SimpleApplet3$1.run(SimpleApplet3.java:26)
      at sun.plugin.dom.DOMService.invokeAndWait(DOMService.java:49)
      at SimpleApplet3.init(SimpleApplet3.java:22)
      at sun.applet.AppletPanel.run(AppletPanel.java:344)
      at java.lang.Thread.run(Thread.java:539)
      com.sun.java.browser.dom.DOMUnsupportedException
      at sun.plugin.dom.DOMServiceProvider.getDocument(DOMServiceProvider.java:79)
      at sun.plugin.dom.DOMAccessor.getDocument(DOMService.java:87)
      at SimpleApplet3$1.run(SimpleApplet3.java:26)
      at sun.plugin.dom.DOMService.invokeAndWait(DOMService.java:49)
      at SimpleApplet3.init(SimpleApplet3.java:22)
      at sun.applet.AppletPanel.run(AppletPanel.java:344)
      at java.lang.Thread.run(Thread.java:539)
      java.lang.NullPointerException
      at SimpleApplet3$1.run(SimpleApplet3.java:27)
      at sun.plugin.dom.DOMService.invokeAndWait(DOMService.java:49)
      at SimpleApplet3.init(SimpleApplet3.java:22)
      at sun.applet.AppletPanel.run(AppletPanel.java:344)
      at java.lang.Thread.run(Thread.java:539)
      (Review ID: 135221)
      ======================================================================

            zgu Zhengyu Gu
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: