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/01/12 00:21:28 UTC

svn commit: r368165 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ tobago-theme/tobago-t...

Author: weber
Date: Wed Jan 11 15:20:43 2006
New Revision: 368165

URL: http://svn.apache.org/viewcvs?rev=368165&view=rev
Log:
unifying of ajax script methods

Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
    incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js
    incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js
    incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
    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-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java Wed Jan 11 15:20:43 2006
@@ -5,7 +5,6 @@
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIViewRoot;
 
-import javax.faces.application.ViewHandler;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseId;
@@ -83,14 +82,6 @@
     }
   }
 
-
-  public static String createUrl(final FacesContext facesContext, final String clientId) {
-    final String viewId = facesContext.getViewRoot().getViewId();
-    final ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
-    final String actionURL = viewHandler.getActionURL(facesContext, viewId);
-    return facesContext.getExternalContext().encodeActionURL(
-        actionURL+"?affectedAjaxComponent=" + clientId);
-  }
 
   public static void processAjax(FacesContext facesContext, UIComponent component)
       throws IOException {

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.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/InRenderer.java?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java Wed Jan 11 15:20:43 2006
@@ -26,6 +26,7 @@
 import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
 import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
 import org.apache.myfaces.tobago.component.ComponentUtil;
+import org.apache.myfaces.tobago.component.UIPage;
 import org.apache.myfaces.tobago.renderkit.HtmlUtils;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
 import org.apache.myfaces.tobago.renderkit.html.InRendererBase;
@@ -129,7 +130,7 @@
       ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
       String actionURL = viewHandler.getActionURL(facesContext, viewId);
 
-//      final UIPage page = ComponentUtil.findPage(input);
+      final UIPage page = ComponentUtil.findPage(input);
 //      page.getScriptFiles().add("script/effects.js");
 //      page.getScriptFiles().add("script/dragdrop.js");
 //      page.getScriptFiles().add("script/controls.js");
@@ -158,8 +159,7 @@
       final String[] cmds = {
           "new Tobago.Autocompleter(",
           "    '" + id + "',",
-          "    '" + popupId + "',",
-          "    '" + AjaxUtils.createUrl(facesContext, id) + "',",
+          "    '" + page.getClientId(facesContext) + "',",
           "    { method:       'post',",
           "      asynchronous: true,",
           "      parameters: '',",

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.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/SheetRenderer.java?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Wed Jan 11 15:20:43 2006
@@ -22,6 +22,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import static org.apache.myfaces.tobago.TobagoConstants.*;
+import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
+import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
 import org.apache.myfaces.tobago.component.*;
 import org.apache.myfaces.tobago.component.UIData;
 import org.apache.myfaces.tobago.config.TobagoConfig;
@@ -36,8 +38,6 @@
 import org.apache.myfaces.tobago.taglib.component.MenuCommandTag;
 import org.apache.myfaces.tobago.util.StringUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
-import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
 
 import javax.faces.application.Application;
 import javax.faces.component.*;
@@ -121,11 +121,10 @@
     } else {
       HtmlRendererUtil.writeStyleLoader(facesContext, styles);
       // add creation of ajax object
-      final String formId
-              = ComponentUtil.findPage(data).getFormId(facesContext);
-      cmds[cmds.length -1] = "new Tobago.Sheet(\"" + sheetId + "\", "
-          + "\"" + formId + "\", "
-          + "\"" + AjaxUtils.createUrl(facesContext, sheetId) + "\");";
+      final String pageId
+              = ComponentUtil.findPage(data).getClientId(facesContext);
+      cmds[cmds.length -1]
+          = "new Tobago.Sheet(\"" + sheetId + "\", \"" + pageId + "\");";
       HtmlRendererUtil.writeScriptLoader(facesContext, scripts, cmds);
     }
   }

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.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/TabGroupRenderer.java?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Wed Jan 11 15:20:43 2006
@@ -149,8 +149,8 @@
 
         if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()
             && SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
-          final String formId
-              = ComponentUtil.findPage(component).getFormId(facesContext);
+          final String pageId
+              = ComponentUtil.findPage(component).getClientId(facesContext);
           final String[] scripts = new String[]{
               "script/tab.js",
               "script/tabgroup.js"
@@ -159,8 +159,7 @@
               "new Tobago.TabGroup(",
               "    '" + clientId + "', ",
               "    '" + activeIndex + "', ",
-              "    '" + formId + "', ",
-              "    '" + AjaxUtils.createUrl(facesContext, clientId) + "');"
+              "    '" + pageId + "');"
           };
           HtmlRendererUtil.writeScriptLoader(facesContext, scripts, cmds);
         }

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.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/inputSuggest.js?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js Wed Jan 11 15:20:43 2006
@@ -18,12 +18,12 @@
 Tobago.Autocompleter = Class.create();
 Tobago.Autocompleter.prototype = Object.extend(new Autocompleter.Base(),
 Object.extend(new Ajax.Base(), {
-  initialize: function(element, update, url, options) {
-	  this.baseInitialize(element, update, options);
+  initialize: function(element, page, options) {
+	  this.baseInitialize(element, $(element).id + Tobago.subComponentSeparator + "ajaxPopup", options);
     this.options.asynchronous = true;
     this.options.onComplete   = this.onComplete.bind(this)
     this.options.method       = 'post';
-    this.url                  = url;
+    this.page                  = $(page);
     this.options.onShow       =
         function(element, update){
           element.autoCompleter.setup();
@@ -53,8 +53,11 @@
 
     this.options.parameters = this.options.callback
         ? this.options.callback(this.element, entry) : entry;
+
+    var form = Tobago.getFormElement(page);
+    var url = form.action + "?affectedAjaxComponent=" + this.element.id;
     LOG.debug("start new request");
-    new Ajax.Request(this.url, this.options);
+    new Ajax.Request(url, this.options);
   },
 
   onComplete: function(request) {

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.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/tabgroup.js?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js Wed Jan 11 15:20:43 2006
@@ -16,12 +16,11 @@
 
 
 Tobago.TabGroupBase = {
-  initialize: function(tabGroupId, activeIndex, form, url) {
+  initialize: function(tabGroupId, activeIndex, page) {
     this.tabGroupId = tabGroupId,
     this.activeIndex = activeIndex;
     this.element = $(tabGroupId + '.' + activeIndex);
-    this.form = $(form);
-    this.url = url;
+    this.page = $(page);
 
     this.options = {
       method: 'post',
@@ -65,17 +64,7 @@
         LOG.warn("aId = " + aId);
       }
 
-      hidden = $(this.form.id + "-action");
-      if (hidden) {
-        hidden.value = this.tabGroupId;
-      }
-      else {
-        LOG.error("No hidden field for actionIndex Id='" + this.form.id + "-action" + "'");
-        LOG.error("aId = " + aId);
-        return;
-      }
-      this.createOverlay(this.parent);
-      new Ajax.Updater(this.parent, this.url+ '&' + Form.serialize(this.form), this.options);
+      Tobago.Updater.update(this.parent, this.page, this.tabGroupId, this.tabGroupId, this.options);
     } else {
       LOG.info("No reload Event");
     }

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.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-sheet.js?rev=368165&r1=368164&r2=368165&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Wed Jan 11 15:20:43 2006
@@ -16,11 +16,10 @@
 
 
 Tobago.SheetBase = {
-  initialize: function(sheetId, form, url) {
+  initialize: function(sheetId, page) {
     this.sheetId = sheetId,
     this.element = $(sheetId + "_outer_div");
-    this.form = $(form);
-    this.url = url;
+    this.page = $(page);
 
     this.options = {
       method: 'post',
@@ -137,15 +136,8 @@
 
   reloadWithAction: function(action) {
     LOG.debug("reload sheet with action \"" + action + "\"");
-    var hidden = $(this.form.id + "-action");
-    if (hidden) {
-      hidden.value = action;
-    } else {
-      LOG.error("No hidden field for form action Id='" + this.form.id + "-action" + "'");
-      return;
-    }
-    this.createOverlay(this.element);
-    new Ajax.Updater(this.element, this.url+ '&' + Form.serialize(this.form), this.options);
+    Tobago.Updater.update(this.element, this.page, action, this.sheetId, this.options);
+
   },
 
   insertPageTarget: function() {

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=368165&r1=368164&r2=368165&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 Wed Jan 11 15:20:43 2006
@@ -133,6 +133,25 @@
         LOG.debug("script.src=" + child.src);
       }
     }
+  },
+
+  getFormElement: function(page) {
+    page = $(page);
+    return $(page.id + Tobago.subComponentSeparator + "form");
+  },
+
+  createOverlay: function(element) {
+    var overlay = document.createElement('div');
+    overlay.style.position = "absolute";
+    overlay.style.top = "0px";
+    overlay.style.left = "0px";
+    overlay.style.width = element.offsetWidth + 'px';
+    overlay.style.height = element.offsetHeight + 'px';
+    overlay.style.cursor = "wait";
+    // TODO: better z-index strategie
+    overlay.style.zIndex = 10000;
+    element.appendChild(overlay);
+    return overlay;
   }
 
 });
@@ -202,6 +221,34 @@
     }
   }
 }
+
+Tobago.Updater = new Object();
+Object.extend(Tobago.Updater, {
+  update: function(container, page, actionId, ajaxComponentId, options) {
+
+    var form = Tobago.getFormElement(page);
+    if (!form) {
+      LOG.error("Can't find form Tag!");
+      return;
+    }
+
+    var hidden = $(form.id + "-action");
+    if (hidden) {
+      hidden.value = actionId;
+//      LOG.debug("set action to : \"" + hidden.value + "\"");
+    } else {
+      LOG.error("No hidden field for form action Id='" + form.id + "-action" + "'");
+      return;
+    }
+
+    var url = form.action + "?affectedAjaxComponent=" + ajaxComponentId
+        + '&' + Form.serialize(form);
+
+    Tobago.createOverlay(container);
+    //    LOG.debug("request url = " + url);
+    new Ajax.Updater(container, url, options);
+  }
+});
 
 
 if (typeof(LOG) == "undefined") {