Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Applet Life Cycle not respected in IE browser family

    Description
    After an applet is supposedly destroyed, it's init () and start () methods are called again when in fact they should not be called again.
    I reproduced this with gwt and no smartgwt in the picture, but I am posting anyway in case somebody has a workaround?

    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...

    1. the SmartGWT or SmartClient version and browser version(s) involved;
    SmartGWT 2.3-2010-10-05 and 2.3-2010-12-05
    GWT 2.0.3
    Does not work in IE 6, IE 7, and IE 8
    Works fine in Chrome 8.0.552.224

    I reproduced this with simple GWT code and so I do not think this is a SmartGWT issue, but I figured I'd ask and see if anybody has any advice.
    Here is the GWT groups thread I started:
    http://groups.google.com/group/googl...33ccfbe13c530#

    2. for a server-side problem, the complete logs generated during processing of the request;
    DNA

    3. for a client-side problem, the contents of the Developer Console (see FAQ for usage);
    DNA

    4. if there is a JavaScript error, the stack trace logged in the Developer Console (from Internet Explorer if possible); and
    DNA

    5. sample code.
    Stand-alone case (GWT)
    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;
      }
    }
    Stand-alone case (SmartGWT)
    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.user.client.ui.HTML;
    import com.smartgwt.client.widgets.tab.TabSet;
    import com.smartgwt.client.widgets.tab.Tab;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    
    public class TestAppletLifecycle implements EntryPoint {
    
      // my variables
      private final TabSet tabSet = new TabSet ();
      private int tabNumber = 0;
    
      /**
       * The EntryPoint interface
       */
      public void onModuleLoad () {
    
        // layout
        final VLayout mainLayout = new VLayout ();
        mainLayout.setWidth100 ();
        mainLayout.setHeight100 ();
    
        // add a button to add a tab with an applet
        {
          final IButton button = new IButton ();
          button.setAutoFit (true);
          button.setTitle ("Create Tab with Applet");
          button.addClickHandler (new ClickHandler () {
            public void onClick (final ClickEvent clickEvent) {
    
              createTabWithApplet ();
            }
          });
          mainLayout.addMember (button);
        }
        
        // add a tabset
        tabSet.setWidth100 ();
        tabSet.setHeight100 ();
        mainLayout.addMember (tabSet);
        
        // draw
        GWT.log ("onModuleLoad (): drawing main Layout", null);
        mainLayout.draw ();
      }
    
      /**
       * Creates the first tab
       */
      private void createTabWithApplet () {
    
        // helpers
        GWT.log ("createTabWithApplet (): adding AND loading tab #" + tabNumber, null);
        final VLayout layout = new VLayout ();
        layout.setWidth100 ();
        layout.setHeight100 ();
    
        // add the applet
        final String htmlCode = getAppletHtmlCode ();
        GWT.log ("htmlCode: " + htmlCode);
        final HTML html = new HTML ();
        html.setHTML (htmlCode);
        layout.addMember (html);
    
        // add the tab
        tabNumber ++;
        final Tab tab = new Tab ();
        tab.setTitle ("Tab #" + tabNumber);
        tab.setPane (layout);
        tab.setCanClose (true);
        tabSet.addTab (tab);
        tabSet.selectTab (tab);
      }
    
      /**
       * Uniformely generates the HTML code to render the applet
       * @return String
       */
      private String getAppletHtmlCode () {
    
        final String appletCode = "LifecycleTestApplet";
        final String appletArchive = "/applet.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'" +
          ">";
    
        // close
        htmlCode += "</applet>";
    
        // done
        return htmlCode;
      }
    }
    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);
        }
      }
    }
    GWT Console Logging
    Code:
    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
    Code:
    <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 ()>
    Posts with incomplete information are much more likely to be ignored.
    Last edited by shortpasta; 19 Dec 2010, 05:08.
Working...
X