You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/04/03 16:54:41 UTC

svn commit: r391060 - in /incubator/tobago/trunk/tobago-theme: tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/s...

Author: weber
Date: Mon Apr  3 07:54:38 2006
New Revision: 391060

URL: http://svn.apache.org/viewcvs?rev=391060&view=rev
Log:
fix problem on mozilla with onunload/onexit scripts

Modified:
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
    incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=391060&r1=391059&r2=391060&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Mon Apr  3 07:54:38 2006
@@ -263,8 +263,8 @@
     writer.endElement("head");
     writer.startElement("body", page);
     writer.writeAttribute("onload",
-        "Tobago.init('" + clientId + "', '" + defaultActionId + "');", null);
-    writer.writeAttribute("onunload", "Tobago.onexit();", null);
+        "Tobago.init('" + clientId + "');", null);
+//    writer.writeAttribute("onunload", "Tobago.onexit();", null);
     //this ist for ie to prevent scrollbars where none are needed
     writer.writeAttribute("scroll", "auto", null);
     writer.writeComponentClass();
@@ -297,7 +297,7 @@
         clientId + SUBCOMPONENT_SEP + "form-action");
     writer.writeIdAttribute(
         clientId + SUBCOMPONENT_SEP + "form-action");
-    writer.writeAttribute("value", "", null);
+    writer.writeAttribute("value", defaultActionId, null);
     writer.endElement("input");
 
 // TODO: this is needed for the "BACK-BUTTON-PROBLEM"
@@ -359,16 +359,18 @@
   private void writeEventFunction(
       TobagoResponseWriter writer, Set<String> eventFunctions, String event)
       throws IOException {
-    writer.write("Tobago.applicationOn" + event + " = function() {\n  ");
-    for (String function : eventFunctions) {
-      writer.write(function);
-      if (!function.trim().endsWith(";")) {
-        writer.write(";\n  ");
-      } else {
-        writer.write("\n  ");
+    if (! eventFunctions.isEmpty()) {
+      writer.write("Tobago.applicationOn" + event + " = function() {\n  ");
+      for (String function : eventFunctions) {
+        writer.write(function);
+        if (!function.trim().endsWith(";")) {
+          writer.write(";\n  ");
+        } else {
+          writer.write("\n  ");
+        }
       }
+      writer.write("\n}\n");
     }
-    writer.write("\n}\n");
   }
 
 // ----------------------------------------------------------- business methods

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=391060&r1=391059&r2=391060&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Mon Apr  3 07:54:38 2006
@@ -83,6 +83,8 @@
     */
   scriptLoadingActive: false,
 
+  isSubmit: false,
+
   // -------- Functions -------------------------------------------------------
 
 
@@ -90,18 +92,19 @@
    * Tobagos central init function.
    * Called via onload attribure of body tag
    */
-  init: function(pageId, defaultActionId) {
+  init: function(pageId) {
 //    new LOG.LogArea({hide: false});
 //    LOG.show();
     this.page = this.element(pageId);
     this.form = this.element(this.page.id + this.SUB_COMPONENT_SEP + "form");
+    this.addBindEventListener(this.form, "submit", this, "onSubmit");
     this.action = this.element(this.form.id + '-action')
-    this.action.value = defaultActionId;
-    this.clientDimension
-        = this.createInput("hidden", this.form.id + '-clientDimension');
-    this.form.appendChild(this.clientDimension);
 
-    this.applicationOnload();
+    this.addBindEventListener(window, "unload", this, "onUnload");
+
+    if (this.applicationOnload) {
+      this.applicationOnload();
+    }
 
     this.setFocus();
 
@@ -110,18 +113,28 @@
     this.startScriptLoaders();
   },
 
-  /**
-    * Wrapper function to call application generated onunload function
-    */
-  onunload: function() {
-    Tobago.applicationOnunload();
+  onSubmit: function() {
+    if (!this.isSubmit) {
+      this.isSubmit = true;
+      LOG.debug("set isSubmit to " + this.isSubmit);
+      var clientDimension
+          = this.createInput("hidden", this.form.id + '-clientDimension');
+      clientDimension.value
+          = document.body.clientWidth + ";" + document.body.clientHeight;
+      this.form.appendChild(clientDimension);
+    }
   },
 
   /**
-    * Wrapper function to call application generated onexit function
+    * Wrapper function to call application generated onunload function
     */
-  onexit: function() {
-    Tobago.applicationOnexit();
+  onUnload: function() {
+    LOG.debug("isSubmit is " + this.isSubmit);
+    if (this.isSubmit && this.applicationOnunload) {
+      this.applicationOnunload();
+    } else if (!this.isSubmit && this.applicationOnexit) {
+      this.applicationOnexit();
+    }
   },
 
    /**
@@ -136,21 +149,9 @@
     * Submitting the page with specified actionId.
     */
   submitAction: function(actionId) {
-    this.setAction(actionId);
-    // todo: why this doesn't work?  document.body.onunload = onunloadScript;
-    window.onunload = Tobago.onunload;
-    if (this.form) {
-      this.form.submit();
-    }
-  },
-
-   /**
-    * Set the actionId and clientDimension
-    */
-  setAction: function(actionId) {
     this.action.value = actionId;
-    this.clientDimension.value
-        = document.body.clientWidth + ";" + document.body.clientHeight;
+    this.onSubmit();
+    this.form.submit();
   },
 
    /**