You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2006/02/14 18:43:09 UTC

svn commit: r377783 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ tobago-example/tobago-example-test/ tobago-example/tobago-example-tes...

Author: lofwyr
Date: Tue Feb 14 09:43:07 2006
New Revision: 377783

URL: http://svn.apache.org/viewcvs?rev=377783&view=rev
Log:
insert "onunload" and "onexit" to the page (via script-tag)

Added:
    incubator/tobago/trunk/tobago-example/tobago-example-test/
      - copied from r377676, incubator/tobago/trunk/tobago-example/tobago-example-blank/
    incubator/tobago/trunk/tobago-example/tobago-example-test/pom.xml
      - copied, changed from r377778, incubator/tobago/trunk/tobago-example/tobago-example-blank/pom.xml
    incubator/tobago/trunk/tobago-example/tobago-example-test/src/
      - copied from r377778, incubator/tobago/trunk/tobago-example/tobago-example-blank/src/
    incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/onload.jsp
Removed:
    incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/helloWorld.jsp
Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java
    incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/index.jsp
    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-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago.js

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java?rev=377783&r1=377782&r2=377783&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java Tue Feb 14 09:43:07 2006
@@ -67,6 +67,10 @@
 
   private Set<String> onloadScripts;
 
+  private Set<String> onunloadScripts;
+
+  private Set<String> onexitScripts;
+
   private List<UIPopup> popups;
 
   public UIPage() {
@@ -76,6 +80,8 @@
     styleFiles.add(DEFAULT_STYLE);
     styleBlocks = new ListOrderedSet();
     onloadScripts = new ListOrderedSet();
+    onunloadScripts = new ListOrderedSet();
+    onexitScripts = new ListOrderedSet();
     popups = new ArrayList<UIPopup>();
   }
 
@@ -131,6 +137,8 @@
 
     // clear script Set's
     getOnloadScripts().clear();
+    getOnunloadScripts().clear();
+    getOnexitScripts().clear();
     getScriptBlocks().clear();
 
     // find the form of the action command and set submitted to it and all
@@ -266,6 +274,14 @@
 
   public Set<String> getOnloadScripts() {
     return onloadScripts;
+  }
+
+  public Set<String> getOnunloadScripts() {
+    return onunloadScripts;
+  }
+
+  public Set<String> getOnexitScripts() {
+    return onexitScripts;
   }
 
   public List<UIPopup> getPopups() {

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java?rev=377783&r1=377782&r2=377783&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java Tue Feb 14 09:43:07 2006
@@ -40,6 +40,8 @@
 
   private String file;
   private String onload;
+  private String onunload;
+  private String onexit;
 
   @Override
   public int doEndTag() throws JspException {
@@ -57,6 +59,12 @@
     if (onload != null) {
       page.getOnloadScripts().add(ComponentUtil.getValueFromEl(onload));
     }
+    if (onunload != null) {
+      page.getOnunloadScripts().add(ComponentUtil.getValueFromEl(onunload));
+    }
+    if (onexit != null) {
+      page.getOnexitScripts().add(ComponentUtil.getValueFromEl(onexit));
+    }
     if (bodyContent != null) {
       String script = bodyContent.getString();
       bodyContent.clearBody();
@@ -76,6 +84,8 @@
     super.release();
     file = null;
     onload = null;
+    onunload = null;
+    onexit = null;
   }
 
   public String getFile() {
@@ -102,6 +112,25 @@
   @TagAttribute
   public void setOnload(String onload) {
     this.onload = onload;
+  }
+
+  /**
+   * A script function which is invoked during onUnload Handler on the client,
+   * if the action is a normal submit inside of Tobago.
+   */
+  @TagAttribute
+  public void setOnunload(String onunload) {
+    this.onunload = onunload;
+  }
+
+  /**
+   * A script function which is invoked during onUnload Handler on the client,
+   * when the unload is invoked to a non Tobago page.
+   * E.g. close-button, back-button, entering new url, etc.
+   */
+  @TagAttribute
+  public void setOnexit(String onexit) {
+    this.onexit = onexit;
   }
 }
 

Copied: incubator/tobago/trunk/tobago-example/tobago-example-test/pom.xml (from r377778, incubator/tobago/trunk/tobago-example/tobago-example-blank/pom.xml)
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-test/pom.xml?p2=incubator/tobago/trunk/tobago-example/tobago-example-test/pom.xml&p1=incubator/tobago/trunk/tobago-example/tobago-example-blank/pom.xml&r1=377778&r2=377783&rev=377783&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-blank/pom.xml (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-test/pom.xml Tue Feb 14 09:43:07 2006
@@ -24,11 +24,11 @@
     <artifactId>tobago-example</artifactId>
     <version>1.0.7-SNAPSHOT</version>
   </parent>
-  <artifactId>tobago-example-blank</artifactId>
+  <artifactId>tobago-example-test</artifactId>
   <packaging>war</packaging>
-  <name>Tobago Example Blank</name>
+  <name>Tobago Example Test</name>
   <build>
-    <finalName>tobago-example-blank</finalName>
+    <finalName>tobago-example-test</finalName>
     <plugins>
       <plugin>
         <groupId>org.apache.myfaces.tobago</groupId>

Modified: incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/index.jsp?rev=377783&r1=377778&r2=377783&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/index.jsp (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/index.jsp Tue Feb 14 09:43:07 2006
@@ -13,4 +13,4 @@
  *    See the License for the specific language governing permissions and
  *    limitations under the License.
 --%>
-<jsp:forward page="faces/helloWorld.jsp" />;
+<jsp:forward page="faces/onload.jsp" />;

Added: incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/onload.jsp
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/onload.jsp?rev=377783&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/onload.jsp (added)
+++ incubator/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/onload.jsp Tue Feb 14 09:43:07 2006
@@ -0,0 +1,14 @@
+<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<f:view>
+  <tc:page>
+    <f:facet name="layout">
+      <tc:gridLayout/>
+    </f:facet>
+    <tc:out value="This page demonstrates the use of the onload/onunload/onexit attributes."/>
+    <tc:script onload="alert('onload: You have entered the page');"
+        onunload="alert('onunload: You leave the page to another tobago page');"
+        onexit="alert('onexit: You leave the page to external');" />
+    <tc:button label="click"/>
+  </tc:page>
+</f:view>

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=377783&r1=377782&r2=377783&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 Tue Feb 14 09:43:07 2006
@@ -240,10 +240,8 @@
 //      writer.endElement("script");
     }
 
-    // onload script
     HtmlRendererUtil.startJavascript(writer);
-//    writer.startElement("script", null);
-//    writer.writeAttribute("type", "text/javascript", null);
+    // onload script
     writer.write("function onloadScript() {\n");
     writer.write("onloadScriptDefault();\n");
 
@@ -254,6 +252,22 @@
     writer.write("  Tobago.pageComplete();");
     writer.write("}\n");
 
+    // onunload script
+    writer.write("function onunloadScript() {\n");
+    for (String onunload : page.getOnunloadScripts()) {
+      writer.write(onunload);
+      writer.write('\n');
+    }
+    writer.write("}\n");
+
+    // onexit script
+    writer.write("function onexitScript() {\n");
+    for (String onexit : page.getOnexitScripts()) {
+      writer.write(onexit);
+      writer.write('\n');
+    }
+    writer.write("}\n");
+
     int debugCounter = 0;
     for (String script : page.getScriptBlocks()) {
 
@@ -272,6 +286,7 @@
     writer.endElement("head");
     writer.startElement("body", page);
     writer.writeAttribute("onload", "onloadScript()", null);
+    writer.writeAttribute("onunload", "onexitScript()", null);
     //this ist for ie to prevent scrollbars where none are needed
     writer.writeAttribute("scroll", "auto", null);
     writer.writeComponentClass();

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago.js?rev=377783&r1=377782&r2=377783&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago.js (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago.js Tue Feb 14 09:43:07 2006
@@ -22,6 +22,8 @@
 
 function submitAction(formId, actionId) {
   setAction(formId, actionId);
+// todo: why this doesn't work?  document.body.onunload = onunloadScript;
+  window.onunload = onunloadScript;
   var form = document.getElementById(formId);
   if (form) {
     form.submit();
@@ -198,8 +200,7 @@
 function tbgAddEventListener(element, event, myFunction) {
   if (element.addEventListener) { // this is DOM2
      element.addEventListener(event, myFunction, false);
-  }
-  else { // IE
+  } else { // IE
     element.attachEvent("on" + event, myFunction);
   }
 }