JDK-6939179 : javascript form input field doesn't get focus upon applet starts
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u18
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-03-30
  • Updated: 2011-02-16
  • Resolved: 2010-03-31
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
jdk1.6.0_18 / XP

A DESCRIPTION OF THE PROBLEM :
This minimal html/applet reproduces a bug that was introduced some time after j2sdk1.4.2_17:
<b>document.MYFORM.MYINPUT.focus() fails simply because an applet (<i>any applet</i>) exists.</b>
If the applet is removed, it works.
If I build X.java with j2sdk1.4.2_17, it works.
The problem happens when I build it with jdk1.6.0_18.

In IE, the focus is simply "elsewhere".
FireFox actually places the cursor in the field, but entering keys just results in beeps
(one must click outside the field and then in it again).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
simply display http://OmnipotenceSoftware.com/javabug.htm

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
i expect to be able to type in the form input !
see desc
ACTUAL -
i cannot type in the form input !
see desc

ERROR MESSAGES/STACK TRACES THAT OCCUR :
none - just beeps.
see desc

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.applet.Applet;

public class X extends Applet
{
public synchronized void	init()
	{
	addFocusListener(this);
	}
public synchronized void	start()
	{
	}
public synchronized void	stop()
	{
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If I build X.java with j2sdk1.4.2_17, it works fine.

Release Regression From : 1.4.2_17
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
WORK AROUND 1) Compile the applet as JDK 1.1 or 1.2 version using the -source and -target javac arguments. e.g. javac -source 1.2 -target 1.2 X.java or 2) set the "initial_focus" html parameter to false, e.g. <APPLET CODE="X.class"> <PARAM NAME="initial_focus" VALUE="false"> </APPLET>
31-03-2010

EVALUATION The testcase X.java doesn't compile, got the following compilation error: X.java:8: addFocusListener(java.awt.event.FocusListener) in java.awt.Component cannot be applied to (X) addFocusListener(this); ^ 1 error --- If I changed the above line of code to addFocusListener((java.awt.event.FocusListener)this); it complies but resulting in ClassCastException during runtime Anyway, I don't think the above line of code is relevant to the problem. The problem is reproducible with JRE 1.4.2_17 as well. It isn't a regression but an expected behavior. Applets built with JDK newer than 1.1 or 1.2 version will get focus by default. There is also a applet parameter named "initial_focus" to control whether the applet gets initial focus or not; setting the parameter to false means the applet won't get initial focus and the focus will be set to the javascript textfield as in this testcase.
31-03-2010