Applet Life Cycle not respected in IE browser family

113 views
Skip to first unread message

shortpasta

unread,
Dec 19, 2010, 7:55:50 AM12/19/10
to Google Web Toolkit
Description
After an applet is supposedly destroyed, it's init () and start ()
methods are called again.
Does not work in IE 6, IE 7, and IE 8.
Works fine in Chrome.

Use case:
1. Create a Tab
2. Add an applet
3. Applet's init () and start () methods are called, as expected
4. Close the tab via tabSet.remove ()
5. Applet's stop () and destory () methods are called, as expected
6. Applet's init () and start () methods are called again, NOT as
expected
Not only that, when init () is called, it contains the same applet
parameters specified in #1.
Note that in Chrome, this works fine, meaning that the applet's init
() and start () methods are not called again, and the applet object
seems to be gone from the Java console...

Stand-alone case
[code]
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.HTML;

public class TestAppletLifecycleGwt implements EntryPoint {

// my variables
private int tabNumber = 0;
final TabPanel tabPanel = new TabPanel ();

/**
* The EntryPoint interface
*/
public void onModuleLoad () {

final VerticalPanel verticalPanel = new VerticalPanel ();

// Make a new button that does something when you click it.
final Button button = new Button (
"Create Tab with Applet",
new ClickListener() {
public void onClick (final Widget sender) {

createTabWithApplet ();
}
});
verticalPanel.add (button);

// add a tabset
tabPanel.setWidth ("100%");
tabPanel.setHeight ("100%");
verticalPanel.add (tabPanel);

// draw
GWT.log ("onModuleLoad (): drawing main Layout", null);
RootPanel.get ().add (verticalPanel);
}

/**
* Creates the first tab
*/
private void createTabWithApplet () {

// next tabNumber
tabNumber ++;
GWT.log ("createTabWithApplet (): adding AND loading tab #" +
tabNumber, null);

// organize vertically
final VerticalPanel verticalPanel = new VerticalPanel ();

// add the applet
final String htmlCode = getAppletHtmlCode ();
GWT.log ("htmlCode: " + htmlCode);
final HTML html = new HTML ();
html.setHTML (htmlCode);
verticalPanel.add (html);

// Close button
final Button button = new Button (
"Close",
new ClickListener() {
public void onClick (final Widget sender) {

tabPanel.remove (verticalPanel);
}
});
verticalPanel.add (button);
verticalPanel.setWidth ("100%");
verticalPanel.setHeight ("100%");

// add the tab
tabPanel.add (verticalPanel, "Tab #" + tabNumber);
}

/**
* Uniformely generates the HTML code to render the applet
* @return String
*/
private String getAppletHtmlCode () {

final String appletCode =
"org.shortdesktop.portal.applet.server.test.LifecycleTestApplet";
final String appletArchive = "/applet/shortdesktop-applets.jar";
final String appletId = "LifecycleTestApplet";
final String appletAlign = null;
String htmlCode =
"<applet mayscript='true' " +
(appletArchive != null ?
"archive='" + appletArchive + "' " :
"") +
(appletAlign != null ?
"align='" + appletAlign + "' " :
"") +
"code='" + appletCode + "' " +
// "width='" + appletConfig.getWidth () + "' " +
// "height='" + appletConfig.getHeight () + "' " +
"width='" + "100%" + "' " +
"height='" + "100%" + "' " +
// "name='" + appletConfig.getName () + "' " +
"id='" + appletId + "' " +
"alt='Java Runtime Environment is not working on your system'" +
">";

htmlCode += "<param name='" + "param1" + "' value='" + "value1" +
"'>";

// close
htmlCode += "</applet>";

// done
return htmlCode;
}
}
[/code]

Applet:
[code]
import java.util.Date;
import java.awt.Color;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JTextField;
import javax.swing.border.Border;

public class LifecycleTestApplet extends JApplet {

// my attributes
private JTextField textField;

/**
* The Applet interface
*/
@Override
public void init () {

// helper
log ("init ()");

// delegate
super.init ();

// log param1
final String value1 = getParameter ("param1");
log ("init (): param1=" + value1);


// create simple UI
final JPanel panel = new JPanel ();
final String title = "LifecycleTestApplet";
final Border border = BorderFactory.createTitledBorder (title);
panel.setBorder (border);
panel.setBackground (Color.WHITE);

// add a log lines
final Box box = Box.createVerticalBox ();
textField = new JTextField (40);
textField.setHorizontalAlignment (JTextField.LEFT);
textField.setEditable (false);
box.add (textField);
}

/**
* The Applet interface
*/
@Override
public void start () {

// helper
log ("start ()");

// delegate
super.start ();
}

/**
* The Applet interface
*/
@Override
public void stop () {

// helper
log ("stop ()");

// delegate
super.stop ();
}

/**
* The Applet interface
*/
@Override
public void destroy () {

// helper
log ("destroy ()");

// delegate
super.destroy ();
}

/**
* Uniformely logs the given message
* @param message
*/
private void log (final String message) {

System.out.println ("<" + new Date () + ">");
System.out.println ("<" + toString () + ">");
System.out.println ("<identityHashCode: " +
System.identityHashCode (this) + "> ");
System.out.println ("<" + message + ">");
if (textField != null) {
textField.setText (message);
}
}
}
[/code]

GWT Console Logging
00:00:38.719 [INFO] Loading module portal
00:00:43.375 [INFO] onModuleLoad (): drawing main Layout
00:00:43.375 [INFO] onModuleLoad (): drawing main Layout
00:00:43.375 [INFO] onModuleLoad (): drawing main Layout
00:00:51.406 [INFO] htmlCode: <applet mayscript='true' archive='/
applet.jar' code='LifecycleTestApplet' width='100%' height='100%'
id='LifecycleTestApplet' alt='Java Runtime Environment is not working
on your system'><param name='param1' value='value1'></applet>

Java Console Logging
<Sun Dec 19 04:53:26 PST 2010>
<LifecycleTestApplet[panel0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,0x0,invalid,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 16602326>
<init ()>
<Sun Dec 19 04:53:26 PST 2010>
<LifecycleTestApplet[panel0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,0x0,invalid,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 16602326>
<init (): param1=value1>
<Sun Dec 19 04:53:26 PST 2010>
<LifecycleTestApplet[panel0,0,0,0x0,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,0x0,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 16602326>
<start ()>
<Sun Dec 19 04:53:29 PST 2010>
<LifecycleTestApplet[panel0,0,0,235x1,hidden,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,235x1,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 16602326>
<stop ()>
<Sun Dec 19 04:53:29 PST 2010>
<LifecycleTestApplet[panel0,0,0,235x1,hidden,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,235x1,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 16602326>
<destroy ()>
<Sun Dec 19 04:53:29 PST 2010>
<LifecycleTestApplet[panel1,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,0x0,invalid,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 24408544>
<init ()>
<Sun Dec 19 04:53:29 PST 2010>
<LifecycleTestApplet[panel1,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,0x0,invalid,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 24408544>
<init (): param1=value1>
<Sun Dec 19 04:53:29 PST 2010>
<LifecycleTestApplet[panel1,0,0,0x0,layout=java.awt.BorderLayout,rootPane=javax.swing.JRootPane[,
0,0,0x0,layout=javax.swing.JRootPane
$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
<identityHashCode: 24408544>
<start ()>

shortpasta

unread,
Dec 21, 2010, 11:59:38 AM12/21/10
to Google Web Toolkit
Reply all
Reply to author
Forward
0 new messages