From 3d357ffc844536f1ac9b2a36d4b4e3b224aceb6b Mon Sep 17 00:00:00 2001 From: Eyal Alalouf Date: Thu, 25 Jan 2007 18:12:05 +0000 Subject: [PATCH] Add support for multiple fomrs on the client side in case of TARGET_J2EE portal support. svn path=/trunk/mcs/; revision=71699 --- .../System.Web.UI.WebControls/ChangeLog | 4 ++ .../System.Web.UI.WebControls/TreeView.js | 6 +- mcs/class/System.Web/System.Web.UI/ChangeLog | 11 +++ .../System.Web.UI/ClientScriptManager.cs | 4 +- mcs/class/System.Web/System.Web.UI/Control.cs | 12 +++- .../System.Web/System.Web.UI/Control.jvm.cs | 35 ---------- mcs/class/System.Web/System.Web.UI/Page.cs | 67 ++++++++++--------- .../System.Web/System.Web.UI/Page.jvm.cs | 58 ++++++++-------- mcs/class/System.Web/resources/ChangeLog | 8 +++ .../MaintainScrollPositionOnPostBack.js | 20 +++--- mcs/class/System.Web/resources/callback.js | 7 +- mcs/class/System.Web/resources/webform.js | 36 +++++++--- 12 files changed, 150 insertions(+), 118 deletions(-) diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog index 9c234f31ab5..dad35fb9e74 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog @@ -1,3 +1,7 @@ +2007-01-14 Eyal Alaluf + + * TreeView.js: Used WebForm_GetFormFromCtrl to lookup the form. + 2007-01-24 Vladimir Krasnov * TextBox.cs: implemented AutoCompleteType property, fixed diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.js b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.js index 1d4994f8496..8964c31be64 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.js +++ b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.js @@ -17,7 +17,8 @@ function TreeView_ToggleExpand (treeId, nodeId) { node.style.display = expand ? "block" : "none"; - var inputStates = document.forms[0][treeId + "_ExpandStates"]; + var myForm = WebForm_GetFormFromCtrl (treeId); + var inputStates = myForm [treeId + "_ExpandStates"]; TreeView_SetNodeFlag (inputStates, nodeId, expand); if (tree.showImage) { @@ -59,7 +60,8 @@ function TreeView_PopulateCallback (data, ids) if (data != "*") { node.innerHTML = data; TreeView_ToggleExpand (idArray[0], idArray[1]); - TreeView_SetNodeFlag (document.forms[0][idArray[0] + "_PopulatedStates"], idArray[1], true); + var myForm = WebForm_GetFormFromCtrl (treeId); + TreeView_SetNodeFlag (myForm [idArray[0] + "_PopulatedStates"], idArray[1], true); } else { if (tree.showImage && tree.noExpandImage != null) { var image = document.getElementById (spanId + "_img"); diff --git a/mcs/class/System.Web/System.Web.UI/ChangeLog b/mcs/class/System.Web/System.Web.UI/ChangeLog index 5a4ef78aff1..03aaeb1ebcd 100644 --- a/mcs/class/System.Web/System.Web.UI/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI/ChangeLog @@ -1,3 +1,14 @@ +2007-01-25 Eyal Alaluf + + * Page.cs: Change code to use the 'theForm' property when generating + JavaScript code. Ensure that we pass 'theForm' as param to the JS funcs. + * Page.jvm.cs, Control.jvm.cs: Implement the 'theForm' property to include + the portlet namespace. Moved 'PortletNamespace' from Control.jvm.cs + * Page.jvm.cs, Control.jvm.cs, ClientScriptManager.cs: Added support for + saving hidden fields for TARGET_J2EE Portlets re-render. + * Control.cs: Under TARGET_J2EE portal support add the PortletNamespace + to all the control IDs to ensure they different between portlets. + 2007-01-24 Vladimir Krasnov * Page.cs: fixed CheckForValidationSupport, diff --git a/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs b/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs index cc822687e4f..c9b2e11d35d 100644 --- a/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs +++ b/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs @@ -53,7 +53,7 @@ namespace System.Web.UI Hashtable registeredArrayDeclares; ScriptEntry clientScriptBlocks; ScriptEntry startupScriptBlocks; - Hashtable hiddenFields; + internal Hashtable hiddenFields; ScriptEntry submitStatements; ScriptEntry scriptIncludes; Page page; @@ -99,7 +99,7 @@ namespace System.Web.UI throw new ArgumentNullException ("control"); page.RequiresPostBackScript (); - return String.Format ("{0}('{1}','{2}')", page.PostBackFunctionName, control.UniqueID, argument); + return String.Format ("__doPostBack('{0}','{1}')", control.UniqueID, argument); } #if NET_2_0 diff --git a/mcs/class/System.Web/System.Web.UI/Control.cs b/mcs/class/System.Web/System.Web.UI/Control.cs index e67353f0e21..467f7c6d19f 100644 --- a/mcs/class/System.Web/System.Web.UI/Control.cs +++ b/mcs/class/System.Web/System.Web.UI/Control.cs @@ -443,6 +443,12 @@ namespace System.Web.UI _userId = _namingContainer.GetDefaultName (); string prefix = _namingContainer.UniqueID; +#if TARGET_J2EE + // For J2EE portlets we need to add the namespace to the ID. + if (_namingContainer == _page && _page.PortletNamespace != null) + prefix = _page.PortletNamespace; + else +#endif if (_namingContainer == _page || prefix == null) { uniqueID = _userId; return uniqueID; @@ -574,7 +580,6 @@ namespace System.Web.UI defaultNumberID = 0; } -#if !TARGET_J2EE string GetDefaultName () { string defaultName; @@ -585,7 +590,6 @@ namespace System.Web.UI } return defaultName; } -#endif void NullifyUniqueID () { @@ -740,6 +744,10 @@ namespace System.Web.UI Control LookForControlByName (string id) { +#if TARGET_J2EE + if (this == _page && id != null && id == _page.PortletNamespace) + return this; +#endif if (!HasControls ()) return null; diff --git a/mcs/class/System.Web/System.Web.UI/Control.jvm.cs b/mcs/class/System.Web/System.Web.UI/Control.jvm.cs index 3eff19d50dd..25b2abbd275 100644 --- a/mcs/class/System.Web/System.Web.UI/Control.jvm.cs +++ b/mcs/class/System.Web/System.Web.UI/Control.jvm.cs @@ -35,9 +35,6 @@ namespace System.Web.UI { public partial class Control { - bool _emptyPortletNamespace = false; - string _PortletNamespace = null; - internal bool IsPortletRender { get { @@ -45,38 +42,6 @@ namespace System.Web.UI } } - internal string PortletNamespace - { - get { - if (_emptyPortletNamespace) - return null; - - if (_PortletNamespace == null) { - IPortletResponse portletResponse = GetRenderResponse (); - if (portletResponse != null) - _PortletNamespace = portletResponse.getNamespace (); - _emptyPortletNamespace = _PortletNamespace == null; - } - return _PortletNamespace; - } - } - - // For J2EE Portal we need to use the portlet namespace when we generate control IDs. - string GetDefaultName () - { - string defaultName; - if (defaultNumberID > 99) { - defaultName = "_ctl" + defaultNumberID++; - } else { - defaultName = defaultNameArray [defaultNumberID++]; - } - - if (this != _page) - return defaultName; - - return PortletNamespace + defaultName; - } - // Add a variant for specifying use of portlet resolveRenderUrl internal string ResolveUrl (string relativeUrl, bool usePortletRenderResolve) { diff --git a/mcs/class/System.Web/System.Web.UI/Page.cs b/mcs/class/System.Web/System.Web.UI/Page.cs index 11e914f9890..09ae82db807 100644 --- a/mcs/class/System.Web/System.Web.UI/Page.cs +++ b/mcs/class/System.Web/System.Web.UI/Page.cs @@ -440,9 +440,9 @@ public partial class Page : TemplateControl, IHttpHandler #endif #if !TARGET_J2EE - internal string PostBackFunctionName { + internal string theForm { get { - return "__doPostBack"; + return "theForm"; } } #endif @@ -760,22 +760,21 @@ public partial class Page : TemplateControl, IHttpHandler return null; NameValueCollection coll = null; - if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) { - coll = req.Form; - WebROCollection c = (WebROCollection) coll; - allow_load = !c.GotID; - if (allow_load) { - c.ID = GetTypeHashCode (); - } else { - allow_load = (c.ID == GetTypeHashCode ()); - } - } else { - coll = req.QueryString; - } - + if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) + coll = req.Form; #if TARGET_J2EE - coll = LoadViewStateForPortlet((WebROCollection)coll); + else if (IsPortletRender && req.Form ["__VIEWSTATE"] != null) + coll = req.Form; #endif + else + coll = req.QueryString; + + WebROCollection c = (WebROCollection) coll; + allow_load = !c.GotID; + if (allow_load) + c.ID = GetTypeHashCode (); + else + allow_load = (c.ID == GetTypeHashCode ()); if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null) return null; @@ -951,13 +950,13 @@ public partial class Page : TemplateControl, IHttpHandler StringBuilder script = new StringBuilder (); script.AppendLine (""); @@ -976,13 +975,19 @@ public partial class Page : TemplateControl, IHttpHandler writer.WriteLine (""); @@ -1794,12 +1799,12 @@ public partial class Page : TemplateControl, IHttpHandler if (Form.SubmitDisabledControls) { ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement", - "javascript: return WebForm_OnSubmit();"); + "javascript: return WebForm_OnSubmit(" + theForm + ");"); ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript", @""); diff --git a/mcs/class/System.Web/System.Web.UI/Page.jvm.cs b/mcs/class/System.Web/System.Web.UI/Page.jvm.cs index e9ecfb8580a..2490f59c392 100644 --- a/mcs/class/System.Web/System.Web.UI/Page.jvm.cs +++ b/mcs/class/System.Web/System.Web.UI/Page.jvm.cs @@ -29,55 +29,59 @@ using vmw.@internal.j2ee; using javax.servlet.http; using System.Collections.Specialized; +using System.Globalization; using System.Web.Hosting; namespace System.Web.UI { public partial class Page { - internal string PostBackFunctionName { + bool _emptyPortletNamespace = false; + string _PortletNamespace = null; + + internal string PortletNamespace + { get { -#if LATER // Enable when we fix the jscripts not to reference __doPostBack. - IPortletRenderResponse resp = GetRenderResponse(); - if (resp != null) - return "__doPostBack_" + resp.getNamespace(); -#endif - return "__doPostBack"; + if (_emptyPortletNamespace) + return null; + + if (_PortletNamespace == null) { + IPortletResponse portletResponse = Context.ServletResponse as IPortletResponse; + if (portletResponse != null) + _PortletNamespace = portletResponse.getNamespace (); + _emptyPortletNamespace = _PortletNamespace == null; + } + return _PortletNamespace; } } - // For J2EE portlets we load the view state from the render parameters - WebROCollection LoadViewStateForPortlet(WebROCollection coll) - { - IPortletRenderRequest renderRequest = Context.ServletRequest as IPortletRenderRequest; - if (renderRequest != null && (coll == null || coll ["__VIEWSTATE"] == null)) { - string mode = renderRequest.getPortletMode(); - string viewstate = Context.ServletRequest.getParameter("vmw.viewstate." + mode); - if (viewstate != null) { - if (coll == null) - coll = new WebROCollection(); - else - coll.Unprotect(); - coll["__VIEWSTATE"] = viewstate; - coll.Protect(); - } + internal string theForm { + get { + return "theForm" + PortletNamespace; } - return coll; } - internal bool SaveViewStateForNextPortletRender() + internal bool SaveViewStateForNextPortletRender () { IPortletActionResponse resp = Context.ServletResponse as IPortletActionResponse; IPortletActionRequest req = Context.ServletRequest as IPortletActionRequest; if (req == null) return false; - if (IsPostBack && String.Compare (Request.HttpMethod, "POST", true) == 0 && !resp.isRedirected()) - resp.setRenderParameter("vmw.viewstate." + req.getPortletMode(), GetSavedViewState()); + // When redirecting don't save the page viewstate and hidden fields + if (resp.isRedirected ()) + return true; + + if (IsPostBack && 0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) { + resp.setRenderParameter ("__VIEWSTATE", GetSavedViewState ()); + if (ClientScript.hiddenFields != null) + foreach (string key in ClientScript.hiddenFields.Keys) + resp.setRenderParameter (key, (string) ClientScript.hiddenFields [key]); + } // Stop processing only if we are handling processAction. If we // are handling a postback from render then fall through. - return req.processActionOnly() || resp.isRedirected(); + return req.processActionOnly (); } } } diff --git a/mcs/class/System.Web/resources/ChangeLog b/mcs/class/System.Web/resources/ChangeLog index 48a2bd4720a..a217ea4aef7 100644 --- a/mcs/class/System.Web/resources/ChangeLog +++ b/mcs/class/System.Web/resources/ChangeLog @@ -1,3 +1,11 @@ +2007-01-25 Eyal Alaluf + + * MaintainScrollPositionOnPostBack.js, callback.js, webform.js: Under + TARGET_J2EE portlet support we may have more then one ASP.Net form in a + client page. Modify code to not assume we have a global 'theForm' + variable. We either lookup the form using the control ID and DOM hierarchy + or we receive it as an optional parameter to the function. + 2006-12-31 Igor Zelmanovich * webform.js: WebForm_AutoFocus support for not focusable elements diff --git a/mcs/class/System.Web/resources/MaintainScrollPositionOnPostBack.js b/mcs/class/System.Web/resources/MaintainScrollPositionOnPostBack.js index 8be01af6718..f542b80d39a 100644 --- a/mcs/class/System.Web/resources/MaintainScrollPositionOnPostBack.js +++ b/mcs/class/System.Web/resources/MaintainScrollPositionOnPostBack.js @@ -1,23 +1,27 @@ function WebForm_SaveScrollPositionSubmit() { - theForm.elements['__SCROLLPOSITIONX'].value = WebForm_GetScrollX(); - theForm.elements['__SCROLLPOSITIONY'].value = WebForm_GetScrollY(); + this.elements['__SCROLLPOSITIONX'].value = WebForm_GetScrollX(); + this.elements['__SCROLLPOSITIONY'].value = WebForm_GetScrollY(); if ((typeof(this.oldSubmit) != "undefined") && (this.oldSubmit != null)) { return this.oldSubmit(); } return true; } function WebForm_SaveScrollPositionOnSubmit() { - theForm.elements['__SCROLLPOSITIONX'].value = WebForm_GetScrollX(); - theForm.elements['__SCROLLPOSITIONY'].value = WebForm_GetScrollY(); + this.elements['__SCROLLPOSITIONX'].value = WebForm_GetScrollX(); + this.elements['__SCROLLPOSITIONY'].value = WebForm_GetScrollY(); if ((typeof(this.oldOnSubmit) != "undefined") && (this.oldOnSubmit != null)) { return this.oldOnSubmit(); } return true; } -function WebForm_RestoreScrollPosition() { - window.scrollTo(theForm.elements['__SCROLLPOSITIONX'].value, theForm.elements['__SCROLLPOSITIONY'].value); - if ((typeof(theForm.oldOnLoad) != "undefined") && (theForm.oldOnLoad != null)) { - return theForm.oldOnLoad(); +function WebForm_RestoreScrollPosition(currForm) { + currForm = currForm || theForm; + var ScrollX = currForm.elements['__SCROLLPOSITIONX'].value; + var ScrollY = currForm.elements['__SCROLLPOSITIONY'].value; + if (ScrollX != "" || ScrollY != "") + window.scrollTo(ScrollX, ScrollY); + if ((typeof(this.oldOnLoad) != "undefined") && (this.oldOnLoad != null)) { + return this.oldOnLoad(); } return true; } diff --git a/mcs/class/System.Web/resources/callback.js b/mcs/class/System.Web/resources/callback.js index 0523d8683a5..789d7d12d76 100644 --- a/mcs/class/System.Web/resources/callback.js +++ b/mcs/class/System.Web/resources/callback.js @@ -1,7 +1,8 @@ - function WebForm_DoCallback (id, arg, callback, ctx, errorCallback) { - var qs = WebForm_getFormData () + "&__CALLBACKTARGET=" + id + "&&__CALLBACKARGUMENT=" + escape(arg); + var myForm = WebForm_GetFormFromCtrl (id); + var qs = WebForm_getFormData (myForm) + "&__CALLBACKTARGET=" + id + "&&__CALLBACKARGUMENT=" + escape(arg); + // WebForm_httpPost (myForm.serverURL, qs, function (httpPost) { WebForm_ClientCallback (httpPost, ctx, callback, errorCallback); }); WebForm_httpPost (document.URL, qs, function (httpPost) { WebForm_ClientCallback (httpPost, ctx, callback, errorCallback); }); } @@ -17,7 +18,7 @@ function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback) callback (doc, ctx); } -function WebForm_getFormData () +function WebForm_getFormData (theForm) { var qs = ""; var len = theForm.elements.length; diff --git a/mcs/class/System.Web/resources/webform.js b/mcs/class/System.Web/resources/webform.js index 133b55cebfb..998b5031932 100644 --- a/mcs/class/System.Web/resources/webform.js +++ b/mcs/class/System.Web/resources/webform.js @@ -30,8 +30,7 @@ function WebForm_AutoFocus (id) { - var x = document.getElementById ? document.getElementById (id) : - ((document.all) ? document.all [id] : null); + var x = WebForm_GetElementById (id); if (x && (!WebForm_CanFocus(x))) { x = WebForm_FindFirstFocusableChild(x); @@ -95,13 +94,14 @@ function wasControlEnabled (id) return false; } -function WebForm_ReEnableControls() +function WebForm_ReEnableControls (currForm) { - if (typeof (theForm) == 'undefined') + currForm = currForm || theForm; + if (typeof (currForm) == 'undefined') return; - for (var i = 0; i < theForm.childNodes.length; i ++) { - var node = theForm.childNodes[i]; + for (var i = 0; i < currForm.childNodes.length; i ++) { + var node = currForm.childNodes[i]; if (node.disabled && wasControlEnabled (node.id)) node.disabled = false; } @@ -112,13 +112,33 @@ function WebForm_DoPostback (ctrl, par, url, apb, pval, tf, csubm, vg) if (pval && typeof(Page_ClientValidate) == "function" && !Page_ClientValidate(vg)) return; + var form = WebForm_GetFormFromCtrl (ctrl); if (url != null) - theForm.action = url; + form.action = url; if (csubm) __doPostBack (ctrl, par); } +function WebForm_GetFormFromCtrl (id) +{ + // We need to translate the id from ASPX UniqueID to its ClientID. + var ctrl = WebForm_GetElementById (id.replace(/:/g, "_")); + while (ctrl != null) { + if (ctrl.isAspForm) + return ctrl; + ctrl = ctrl.parentNode; + } + return theForm; +} + +function WebForm_GetElementById (id) +{ + return document.getElementById ? document.getElementById (id) : + document.all ? document.all [id] : + document [id]; +} + function WebForm_FireDefaultButton(event, target) { if (event.keyCode != 13) { @@ -127,7 +147,7 @@ function WebForm_FireDefaultButton(event, target) if(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")) { return true; } - var defaultButton = document.getElementById(target); + var defaultButton = WebForm_GetElementById(target); if (defaultButton && typeof(defaultButton.click) != "undefined") { defaultButton.click(); event.cancelBubble = true; -- 2.25.1