From: Eyal Alalouf Date: Sun, 18 Feb 2007 12:28:38 +0000 (-0000) Subject: add Http callback support for J2EE portlets. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=9396a912275a564e0800cfe62cd6ff8faa895899;p=mono.git add Http callback support for J2EE portlets. svn path=/trunk/mcs/; revision=73071 --- diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog index 6c9d72dc01b..9c5a4ced2c2 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog @@ -1,3 +1,8 @@ +2007-02-18 Eyal Alaluf + + * HtmlForm.cs: Under TARGET_J2EE use Page.RenderResponse instead of + GetRenderResponse. + 2007-01-20 Miguel de Icaza * HtmlHead.cs: comment out unused code, in particular metadata is @@ -11,7 +16,7 @@ 2007-01-14 Eyal Alaluf - * HtmlForm.cs, HtmlAnchor.cs: Added H2EE Portal support for TARGET_J2EE. + * HtmlForm.cs, HtmlAnchor.cs: Added J2EE Portal support for TARGET_J2EE. 2007-01-14 Eyal Alaluf diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlForm.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlForm.cs index e5661da62ed..2b72c790833 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlForm.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlForm.cs @@ -251,9 +251,9 @@ namespace System.Web.UI.HtmlControls action += Page.Request.QueryStringRaw; #if TARGET_J2EE - vmw.@internal.j2ee.IPortletRenderResponse resp = GetRenderResponse(); - if (resp != null) - action = resp.createActionURL(action); + // Allow the page to transform action to a portlet action url + if (Page.IsPortletRender) + action = Page.RenderResponse.createActionURL(action); #endif w.WriteAttribute ("name", Name); diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs b/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs index 45960618438..9cab6b54df9 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs @@ -218,11 +218,6 @@ namespace System.Web.UI.WebControls { { PostBackOptions options = new PostBackOptions (this); options.ActionUrl = (PostBackUrl.Length > 0 ? Page.ResolveClientUrl (PostBackUrl) : null); -#if TARGET_J2EE - vmw.@internal.j2ee.IPortletRenderResponse resp = GetRenderResponse(); - if (resp != null && options.ActionUrl != null) - options.ActionUrl = resp.createActionURL(options.ActionUrl); -#endif options.ValidationGroup = null; options.Argument = ""; options.RequiresJavaScriptProtocol = false; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog index 4d859751099..f7632161258 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog @@ -1,3 +1,12 @@ +2007-02-18 Eyal Alaluf + + * Button.cs, ImageButton.cs, LinkButton.cs: Hanlding of PostbackOptions for + TARGET_J2EE is now centralized in ClientScriptManager. + * TreeView.cs, DetailsView.cs, GridView.cs, TreeView.js, DetailsView.js, + GridView.js: Added a field to the controls JavaScript 'data' object. The + form is initialized to the page 'theForm'. This is used for J2EE portlets + callback support. + 2006-02-18 Igor Zelmanovich * Wizard: fixed: diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs index df151411a1a..f3bd3f0fb80 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs @@ -1914,6 +1914,7 @@ namespace System.Web.UI.WebControls string script = string.Format ("var {0} = new Object ();\n", cgrid); script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex)); script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID)); + script += string.Format ("{0}.form = {1};\n", cgrid, Page.theForm); Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true); // Make sure the basic script infrastructure is rendered diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.js b/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.js index 406007a2339..35889a02f23 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.js +++ b/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.js @@ -4,7 +4,7 @@ function DetailsView_ClientEvent (ctrlId, evnt) if (!gridData) return null; var clientData = gridData.pageIndex + '|' + evnt; - WebForm_DoCallback (gridData.uid, clientData, DetailsView_ClientRender, ctrlId, DetailsView_ClientRender_Error); + WebForm_DoCallback (gridData.uid, clientData, DetailsView_ClientRender, ctrlId, DetailsView_ClientRender_Error, gridData.form); } function DetailsView_ClientRender (data, ctx) diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs index cba4cd4c0c1..e9ee9e18b9f 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs @@ -2076,6 +2076,7 @@ namespace System.Web.UI.WebControls script += string.Format ("{0}.sortExp = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (SortExpression == null ? "" : SortExpression)); script += string.Format ("{0}.sortDir = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral ((int) SortDirection)); script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID)); + script += string.Format ("{0}.form = {1};\n", cgrid, Page.theForm); Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true); // Make sure the basic script infrastructure is rendered diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.js b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.js index 52857f28593..e1e35d94658 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.js +++ b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.js @@ -4,7 +4,7 @@ function GridView_ClientEvent (ctrlId, evnt) if (!gridData) return null; var clientData = gridData.pageIndex + '|' + escape (gridData.sortExp) + '|' + gridData.sortDir + '|' + evnt; - WebForm_DoCallback (gridData.uid, clientData, GridView_ClientRender, ctrlId, GridView_ClientRender_Error); + WebForm_DoCallback (gridData.uid, clientData, GridView_ClientRender, ctrlId, GridView_ClientRender_Error, gridData.form); } function GridView_ClientRender (data, ctx) diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs index fb0e242ba82..5596f835322 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs @@ -244,11 +244,6 @@ namespace System.Web.UI.WebControls { { PostBackOptions options = new PostBackOptions (this); options.ActionUrl = (PostBackUrl.Length > 0 ? Page.ResolveClientUrl (PostBackUrl) : null); -#if TARGET_J2EE - vmw.@internal.j2ee.IPortletRenderResponse resp = GetRenderResponse(); - if (resp != null && options.ActionUrl != null) - options.ActionUrl = resp.createActionURL(options.ActionUrl); -#endif options.ValidationGroup = null; options.Argument = ""; options.ClientSubmit = false; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs b/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs index db84255dd5d..47b472e6543 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs @@ -144,11 +144,6 @@ namespace System.Web.UI.WebControls { { PostBackOptions options = new PostBackOptions (this); options.ActionUrl = (PostBackUrl.Length > 0 ? Page.ResolveClientUrl (PostBackUrl) : null); -#if TARGET_J2EE - vmw.@internal.j2ee.IPortletRenderResponse resp = GetRenderResponse(); - if (resp != null && options.ActionUrl != null) - options.ActionUrl = resp.createActionURL(options.ActionUrl); -#endif options.ValidationGroup = null; options.Argument = ""; options.ClientSubmit = true; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs index b47b87226be..7c9991d3ded 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs @@ -1068,6 +1068,7 @@ namespace System.Web.UI.WebControls } if (Page != null) { + script += string.Format ("{0}.form = {1};\n", ctree, Page.theForm); script += string.Format ("{0}.populateFromClient = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (PopulateNodesFromClient)); script += string.Format ("{0}.expandAlt = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (true, null))); script += string.Format ("{0}.collapseAlt = {1};\n", ctree, ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (false, null))); 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 1dd426efd4c..4ac79d72f3d 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.js +++ b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.js @@ -8,7 +8,7 @@ function TreeView_ToggleExpand (treeId, nodeId) { var expand = node.style.display == "none"; if (tree.populateFromClient && expand && node.populated != true && (node.innerHTML.length == 0 || node.hasError)) { - WebForm_DoCallback (tree.uid, nodeId, TreeView_PopulateCallback, treeId + " " + nodeId, TreeView_PopulateCallback) + WebForm_DoCallback (tree.uid, nodeId, TreeView_PopulateCallback, treeId + " " + nodeId, TreeView_PopulateCallback, tree.form) return; } @@ -17,8 +17,7 @@ function TreeView_ToggleExpand (treeId, nodeId) { node.style.display = expand ? "block" : "none"; - var myForm = WebForm_GetFormFromCtrl (treeId); - var inputStates = myForm [treeId + "_ExpandStates"]; + var inputStates = tree.form [treeId + "_ExpandStates"]; TreeView_SetNodeFlag (inputStates, nodeId, expand); if (tree.showImage) { @@ -60,8 +59,7 @@ function TreeView_PopulateCallback (data, ids) if (data != "*") { node.innerHTML = data; TreeView_ToggleExpand (idArray[0], idArray[1]); - var myForm = WebForm_GetFormFromCtrl (idArray[0]); - TreeView_SetNodeFlag (myForm [idArray[0] + "_PopulatedStates"], idArray[1], true); + TreeView_SetNodeFlag (tree.form [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 8d4d3f832ce..d8bf5cda01d 100644 --- a/mcs/class/System.Web/System.Web.UI/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI/ChangeLog @@ -1,3 +1,10 @@ +2007-02-18 Eyal Alaluf + + * Control.jvm.cs, Control.cs: Move TemplateSourceDirectory to .jvm file. + * Control.jvm.cs, Page.jvm.cs: Centralize Portlet specific API in Page.jvm + * Page.cs, Page.jvm.cs, ClientScriptManager.cs: Support for Http callbacks + for J2EE portlets. + 2007-02-14 Igor Zelmanovich * Page.cs: for 2.0: diff --git a/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs b/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs index 392bbe1e208..6ff81feb4f4 100644 --- a/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs +++ b/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs @@ -131,7 +131,7 @@ namespace System.Web.UI { if (options == null) throw new ArgumentNullException ("options"); - + if (options.ActionUrl == null && options.ValidationGroup == null && !options.TrackFocus && !options.AutoPostBack && !options.PerformValidation) { @@ -145,20 +145,31 @@ namespace System.Web.UI } RegisterWebFormClientScript (); - - if (options.ActionUrl != null) + + string actionUrl = options.ActionUrl; + if (actionUrl != null) RegisterHiddenField (Page.PreviousPageID, page.Request.FilePath); - - return String.Format ("{0}WebForm_DoPostback({1},{2},{3},{4},{5},{6},{7},{8})", - options.RequiresJavaScriptProtocol ? "javascript:" : "", + + string prefix = options.RequiresJavaScriptProtocol ? "javascript:" : ""; +#if TARGET_J2EE + // Allow the page to transform ActionUrl to a portlet action url + if (actionUrl != null && page.PortletNamespace != null) { + actionUrl = page.CreateActionUrl(actionUrl); + prefix += "Portal"; + } +#endif + + return String.Format ("{0}WebForm_DoPostback({1},{2},{3},{4},{5},{6},{7},{8},{9})", + prefix, ClientScriptManager.GetScriptLiteral (options.TargetControl.UniqueID), ClientScriptManager.GetScriptLiteral (options.Argument), - ClientScriptManager.GetScriptLiteral (options.ActionUrl), + ClientScriptManager.GetScriptLiteral (actionUrl), ClientScriptManager.GetScriptLiteral (options.AutoPostBack), ClientScriptManager.GetScriptLiteral (options.PerformValidation), ClientScriptManager.GetScriptLiteral (options.TrackFocus), ClientScriptManager.GetScriptLiteral (options.ClientSubmit), - ClientScriptManager.GetScriptLiteral (options.ValidationGroup) + ClientScriptManager.GetScriptLiteral (options.ValidationGroup), + page.theForm ); } @@ -195,7 +206,7 @@ namespace System.Web.UI { RegisterWebFormClientScript (); - return string.Format ("WebForm_DoCallback('{0}',{1},{2},{3},{4},{5})", target, argument, clientCallback, context, ((clientErrorCallback == null) ? "null" : clientErrorCallback), (useAsync ? "true" : "false")); + return string.Format ("WebForm_DoCallback('{0}',{1},{2},{3},{4},{5},{6})", target, argument, clientCallback, context, ((clientErrorCallback == null) ? "null" : clientErrorCallback), (useAsync ? "true" : "false"), page.theForm); } #endif diff --git a/mcs/class/System.Web/System.Web.UI/Control.cs b/mcs/class/System.Web/System.Web.UI/Control.cs index 479952cbeea..2ce6f09cdf6 100644 --- a/mcs/class/System.Web/System.Web.UI/Control.cs +++ b/mcs/class/System.Web/System.Web.UI/Control.cs @@ -389,41 +389,7 @@ namespace System.Web.UI } #endif -#if TARGET_JVM - private string _templateSourceDir; - public virtual string TemplateSourceDirectory - { - get - { - int location = 0; - if (_templateSourceDir == null) { - string tempSrcDir = _appRelativeTemplateSourceDirectory; - if (tempSrcDir == null && Parent != null) - tempSrcDir = Parent.TemplateSourceDirectory; - if (tempSrcDir != null && tempSrcDir.Length > 1) { - location = tempSrcDir.IndexOf ('/', 1); - if (location != -1) - tempSrcDir = tempSrcDir.Substring (location + 1); - else - tempSrcDir = string.Empty; - } - string answer = HttpRuntime.AppDomainAppVirtualPath; - if (tempSrcDir == null) - tempSrcDir = ""; - - if (tempSrcDir.Length > 0 && tempSrcDir [tempSrcDir.Length - 1] == '/') - tempSrcDir = tempSrcDir.Substring (0, tempSrcDir.Length - 1); - - if (tempSrcDir.StartsWith ("/") || tempSrcDir.Length == 0) - _templateSourceDir = answer + tempSrcDir; - else - _templateSourceDir = answer + "/" + tempSrcDir; - } - return _templateSourceDir; - } - } - -#else +#if !TARGET_J2EE [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] [Browsable (false)] [WebSysDescription ("A virtual directory containing the parent of the control.")] @@ -761,7 +727,7 @@ namespace System.Web.UI Control LookForControlByName (string id) { #if TARGET_J2EE - if (this == _page && id != null && id == _page.PortletNamespace) + if (this == Page && id != null && id == Page.PortletNamespace) return this; #endif if (!HasControls ()) @@ -1224,7 +1190,7 @@ namespace System.Web.UI string absoluteUrl = ResolveUrl (relativeUrl); #if TARGET_J2EE // There are no relative paths when rendering a J2EE portlet - if (IsPortletRender) + if (Page != null && Page.PortletNamespace != null) return absoluteUrl; #endif if (Context != null && Context.Request != 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 25b2abbd275..f35714e57bc 100644 --- a/mcs/class/System.Web/System.Web.UI/Control.jvm.cs +++ b/mcs/class/System.Web/System.Web.UI/Control.jvm.cs @@ -35,39 +35,56 @@ namespace System.Web.UI { public partial class Control { - internal bool IsPortletRender + private string _templateSourceDir; + + public virtual string TemplateSourceDirectory { - get { - return GetRenderResponse() != null; + get + { + int location = 0; + if (_templateSourceDir == null) { + string tempSrcDir = _appRelativeTemplateSourceDirectory; + if (tempSrcDir == null && Parent != null) + tempSrcDir = Parent.TemplateSourceDirectory; + if (tempSrcDir != null && tempSrcDir.Length > 1) { + location = tempSrcDir.IndexOf ('/', 1); + if (location != -1) + tempSrcDir = tempSrcDir.Substring (location + 1); + else + tempSrcDir = string.Empty; + } + string answer = HttpRuntime.AppDomainAppVirtualPath; + if (tempSrcDir == null) + tempSrcDir = ""; + + if (tempSrcDir.Length > 0 && tempSrcDir [tempSrcDir.Length - 1] == '/') + tempSrcDir = tempSrcDir.Substring (0, tempSrcDir.Length - 1); + + if (tempSrcDir.StartsWith ("/") || tempSrcDir.Length == 0) + _templateSourceDir = answer + tempSrcDir; + else + _templateSourceDir = answer + "/" + tempSrcDir; + } + return _templateSourceDir; } } + // Add a variant for specifying use of portlet resolveRenderUrl internal string ResolveUrl (string relativeUrl, bool usePortletRenderResolve) { relativeUrl = ResolveUrl (relativeUrl); - if (usePortletRenderResolve) { - IPortletRenderResponse resp = GetRenderResponse (); - if (resp != null) - relativeUrl = resp.createRenderURL (relativeUrl); - } + if (usePortletRenderResolve && Page != null) + relativeUrl = Page.CreateRenderUrl (relativeUrl); return relativeUrl; } internal string ResolveClientUrl (string relativeUrl, bool usePortletRenderResolve) { relativeUrl = ResolveClientUrl (relativeUrl); - if (usePortletRenderResolve) { - IPortletRenderResponse resp = GetRenderResponse (); - if (resp != null) - relativeUrl = resp.createRenderURL (relativeUrl); - } + if (usePortletRenderResolve && Page != null) + relativeUrl = Page.CreateRenderUrl (relativeUrl); return relativeUrl; } - - internal IPortletRenderResponse GetRenderResponse () - { - return Context.ServletResponse as IPortletRenderResponse; - } } } diff --git a/mcs/class/System.Web/System.Web.UI/Page.cs b/mcs/class/System.Web/System.Web.UI/Page.cs index 5f9332b667c..3d614486695 100644 --- a/mcs/class/System.Web/System.Web.UI/Page.cs +++ b/mcs/class/System.Web/System.Web.UI/Page.cs @@ -1006,6 +1006,10 @@ public partial class Page : TemplateControl, IHttpHandler writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID); writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID); writer.WriteLine ("\t{0}.isAspForm = true;", theForm); +#if TARGET_J2EE + string serverUrl = Context.ServletResponse.encodeURL (Request.RawUrl); + writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl)); +#endif } internal void OnFormRender (HtmlTextWriter writer, string formUniqueID) @@ -1135,7 +1139,7 @@ public partial class Page : TemplateControl, IHttpHandler } [EditorBrowsable (EditorBrowsableState.Never)] -#if NET_2_0 || TARGET_JVM +#if NET_2_0 public virtual void ProcessRequest (HttpContext context) #else public void ProcessRequest (HttpContext context) @@ -1309,12 +1313,11 @@ public partial class Page : TemplateControl, IHttpHandler #if NET_2_0 _lifeCycle = PageLifeCycle.SaveStateComplete; OnSaveStateComplete (EventArgs.Empty); -#endif - #if TARGET_J2EE - if (SaveViewStateForNextPortletRender()) + if (OnSaveStateCompleteForPortlet ()) return; -#endif +#endif // TARGET_J2EE +#endif // NET_2_0 #if NET_2_0 _lifeCycle = PageLifeCycle.Render; 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 2490f59c392..fb60c850774 100644 --- a/mcs/class/System.Web/System.Web.UI/Page.jvm.cs +++ b/mcs/class/System.Web/System.Web.UI/Page.jvm.cs @@ -27,8 +27,8 @@ // using vmw.@internal.j2ee; -using javax.servlet.http; -using System.Collections.Specialized; +using javax.servlet.http; +using System.Collections.Specialized; using System.Globalization; using System.Web.Hosting; @@ -36,8 +36,16 @@ namespace System.Web.UI { public partial class Page { + const string PageNamespaceKey = "__PAGENAMESPACE"; + const string RenderPageMark = "vmw.render.page="; + const string ActionPageMark = "vmw.action.page="; + static readonly string NextActionPageKey = PortletInternalUtils.NextActionPage; + static readonly string NextRenderPageKey = PortletInternalUtils.NextRenderPage; + bool _emptyPortletNamespace = false; string _PortletNamespace = null; + bool _renderResponseInit = false; + IPortletRenderResponse _renderResponse = null; internal string PortletNamespace { @@ -46,9 +54,14 @@ namespace System.Web.UI return null; if (_PortletNamespace == null) { - IPortletResponse portletResponse = Context.ServletResponse as IPortletResponse; + IPortletResponse portletResponse = null; + if (Context != null) + portletResponse = Context.ServletResponse as IPortletResponse; if (portletResponse != null) _PortletNamespace = portletResponse.getNamespace (); + else if (_requestValueCollection != null && _requestValueCollection [PageNamespaceKey] != null) + _PortletNamespace = _requestValueCollection [PageNamespaceKey]; + _emptyPortletNamespace = _PortletNamespace == null; } return _PortletNamespace; @@ -61,8 +74,77 @@ namespace System.Web.UI } } - internal bool SaveViewStateForNextPortletRender () + internal bool IsPortletRender + { + get { + return RenderResponse != null; + } + } + + internal IPortletRenderResponse RenderResponse + { + get { + if (!_renderResponseInit) { + _renderResponse = Context.ServletResponse as IPortletRenderResponse; + _renderResponseInit = true; + } + return _renderResponse; + } + } + + public string CreateRenderUrl (string url) + { + if (RenderResponse != null) + return RenderResponse.createRenderURL (url); + if (PortletNamespace == null) + return url; + + string internalUrl = RemoveAppPathIfInternal (url); + if (internalUrl == null) + return url; + + PostBackOptions options = new PostBackOptions (this); + options.ActionUrl = RenderPageMark + internalUrl; + options.RequiresJavaScriptProtocol = true; + return ClientScript.GetPostBackEventReference (options); + } + + public string CreateActionUrl (string url) + { + if (url.StartsWith(RenderPageMark) || url.StartsWith(ActionPageMark)) + return url; + + if (RenderResponse != null) + return RenderResponse.createActionURL (url); + if (PortletNamespace == null) + return url; + + Uri requestUrl = Request.Url; + string internalUrl = RemoveAppPathIfInternal (url); + if (internalUrl == null) + return url; + + return ActionPageMark + internalUrl; + } + + private string RemoveAppPathIfInternal (string url) { + Uri reqUrl = Request.Url; + string appPath = Request.ApplicationPath; + string currPage = Request.CurrentExecutionFilePath; + if (currPage.StartsWith (appPath)) + currPage = currPage.Substring (appPath.Length); + return PortletInternalUtils.mapPathIfInternal (url, reqUrl.Host, reqUrl.Port, reqUrl.Scheme, appPath, currPage); + } + + internal bool OnSaveStateCompleteForPortlet () + { + if (PortletNamespace != null) { + ClientScript.RegisterHiddenField (PageNamespaceKey, PortletNamespace); + ClientScript.RegisterHiddenField (NextActionPageKey, ""); + ClientScript.RegisterHiddenField (NextRenderPageKey, ""); + } + IPortletActionResponse resp = Context.ServletResponse as IPortletActionResponse; IPortletActionRequest req = Context.ServletRequest as IPortletActionRequest; if (req == null) diff --git a/mcs/class/System.Web/Test/System.Web.UI/ClientScriptManagerTest.cs b/mcs/class/System.Web/Test/System.Web.UI/ClientScriptManagerTest.cs index 1fd068cb4ac..f86736c556a 100644 --- a/mcs/class/System.Web/Test/System.Web.UI/ClientScriptManagerTest.cs +++ b/mcs/class/System.Web/Test/System.Web.UI/ClientScriptManagerTest.cs @@ -85,17 +85,19 @@ namespace MonoTests.System.Web.UI { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; - StringBuilder context1 = new StringBuilder (); - context1.Append ("function ReceiveServerData1(arg, context)"); - context1.Append ("{"); - context1.Append ("Message1.innerText = arg;"); - context1.Append ("value1 = arg;"); - context1.Append ("}"); + StringBuilder func = new StringBuilder (); + func.Append ("function ReceiveServerData1(arg, context)"); + func.Append ("{"); + func.Append ("Message1.innerText = arg;"); + func.Append ("value1 = arg;"); + func.Append ("}"); // Define callback references. - String cbReference = cs.GetCallbackEventReference (p, "arg", - "ReceiveServerData1", context1.ToString ()); - Assert.AreEqual ("WebForm_DoCallback('__Page',arg,ReceiveServerData1,function ReceiveServerData1(arg, context){Message1.innerText = arg;value1 = arg;},null,false)", cbReference, "GetCallbackEventReferenceFail1"); + String cbReference = cs.GetCallbackEventReference (p, "callArg", + func.ToString (), "ReceiveServerData1Ctx"); + Assert.IsTrue (cbReference.IndexOf ("callArg") != -1, "GetCallbackEventReferenceFail1_arg"); + Assert.IsTrue (cbReference.IndexOf (func.ToString ()) != -1, "GetCallbackEventReferenceFail1_callback"); + Assert.IsTrue (cbReference.IndexOf ("ReceiveServerData1Ctx") != -1, "GetCallbackEventReferenceFail1_context"); } [Test] @@ -103,17 +105,23 @@ namespace MonoTests.System.Web.UI { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; - StringBuilder context1 = new StringBuilder (); - context1.Append ("function ReceiveServerData1(arg, context)"); - context1.Append ("{"); - context1.Append ("Message1.innerText = arg;"); - context1.Append ("value1 = arg;"); - context1.Append ("}"); + StringBuilder func = new StringBuilder (); + func.Append ("function ReceiveServerData1(arg, context)"); + func.Append ("{"); + func.Append ("Message1.innerText = arg;"); + func.Append ("value1 = arg;"); + func.Append ("}"); // Define callback references. - String cbReference = cs.GetCallbackEventReference (p, "arg", - "ReceiveServerData1", context1.ToString (), true); - Assert.AreEqual ("WebForm_DoCallback('__Page',arg,ReceiveServerData1,function ReceiveServerData1(arg, context){Message1.innerText = arg;value1 = arg;},null,true)", cbReference, "GetCallbackEventReferenceFail2"); + String cbReference = cs.GetCallbackEventReference (p, "callArg", + func.ToString (), "ReceiveServerData1Ctx", true); + Assert.IsTrue (cbReference.IndexOf ("callArg") != -1, "GetCallbackEventReferenceFail2_arg"); + Assert.IsTrue (cbReference.IndexOf (func.ToString ()) != -1, "GetCallbackEventReferenceFail2_callback"); + Assert.IsTrue (cbReference.IndexOf ("ReceiveServerData1Ctx") != -1, "GetCallbackEventReferenceFail2_context"); + String cbReference2 = cs.GetCallbackEventReference (p, "arg", + func.ToString (), "ReceiveServerData1Ctx", false); + // Check that we get different results when useAsync differs. + Assert.IsTrue (cbReference != cbReference2, "GetCallbackEventReferenceFail2_useAsync"); } [Test] @@ -121,17 +129,20 @@ namespace MonoTests.System.Web.UI { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; - StringBuilder context1 = new StringBuilder (); - context1.Append ("function ReceiveServerData1(arg, context)"); - context1.Append ("{"); - context1.Append ("Message1.innerText = arg;"); - context1.Append ("value1 = arg;"); - context1.Append ("}"); + StringBuilder func = new StringBuilder (); + func.Append ("function ReceiveServerData1(arg, context)"); + func.Append ("{"); + func.Append ("Message1.innerText = arg;"); + func.Append ("value1 = arg;"); + func.Append ("}"); // Define callback references. - String cbReference = cs.GetCallbackEventReference (p, "arg", - "ReceiveServerData1", context1.ToString (), "ErrorCallback", false); - Assert.AreEqual ("WebForm_DoCallback('__Page',arg,ReceiveServerData1,function ReceiveServerData1(arg, context){Message1.innerText = arg;value1 = arg;},ErrorCallback,false)", cbReference, "GetCallbackEventReferenceFail3"); + String cbReference = cs.GetCallbackEventReference (p, "callArg", + func.ToString (), "ReceiveServerData1Ctx", "ErrorCallback", false); + Assert.IsTrue (cbReference.IndexOf ("callArg") != -1, "GetCallbackEventReferenceFail3_arg"); + Assert.IsTrue (cbReference.IndexOf (func.ToString ()) != -1, "GetCallbackEventReferenceFail3_callback"); + Assert.IsTrue (cbReference.IndexOf ("ReceiveServerData1Ctx") != -1, "GetCallbackEventReferenceFail3_context"); + Assert.IsTrue (cbReference.IndexOf ("ErrorCallback") != -1, "GetCallbackEventReferenceFail3_errorCallback"); } [Test] @@ -139,8 +150,9 @@ namespace MonoTests.System.Web.UI { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; - String result = cs.GetPostBackEventReference (new PostBackOptions (p, "args")); - Assert.AreEqual ("__doPostBack('__Page','args')", result, "GetPostBackEventReference#1"); + String result = cs.GetPostBackEventReference (new PostBackOptions (p, "args1")); + Assert.IsTrue (result.IndexOf(p.ClientID) != -1, "GetPostBackEventReference#1_targetEvent"); + Assert.IsTrue (result.IndexOf("args1") != -1, "GetPostBackEventReference#1_targetArgs"); } [Test] @@ -148,8 +160,9 @@ namespace MonoTests.System.Web.UI { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; - String result = cs.GetPostBackEventReference (p, "args"); - Assert.AreEqual ("__doPostBack('__Page','args')", result, "GetPostBackEventReference#2"); + String result = cs.GetPostBackEventReference (p, "args1"); + Assert.IsTrue (result.IndexOf(p.ClientID) != -1, "GetPostBackEventReference#2_targetEvent"); + Assert.IsTrue (result.IndexOf("args1") != -1, "GetPostBackEventReference#2_targetArgs"); } [Test] @@ -157,8 +170,10 @@ namespace MonoTests.System.Web.UI { MyPage p = new MyPage (); ClientScriptManager cs = p.ClientScript; - String hyperlink = cs.GetPostBackClientHyperlink (p, "args"); - Assert.AreEqual ("javascript:__doPostBack('__Page','args')", hyperlink, "GetPostBackClientHyperlink"); + String hyperlink = cs.GetPostBackClientHyperlink (p, "args1"); + Assert.IsTrue (hyperlink.IndexOf("javascript:") != -1, "GetPostBackClientHyperlink_javaScript"); + Assert.IsTrue (hyperlink.IndexOf(p.ClientID) != -1, "GetPostBackClientHyperlink_targetEvent"); + Assert.IsTrue (hyperlink.IndexOf("args1") != -1, "GetPostBackClientHyperlink_targetArgs"); } [Test] diff --git a/mcs/class/System.Web/resources/ChangeLog b/mcs/class/System.Web/resources/ChangeLog index f6bb39ebe75..b258ed99892 100644 --- a/mcs/class/System.Web/resources/ChangeLog +++ b/mcs/class/System.Web/resources/ChangeLog @@ -1,3 +1,8 @@ +2007-02-18 Eyal Alaluf + + * webform.js: Adding an optional parameter for passing the form to all JS + methods. This is needed to support Http callbacks for J2EE portlets. + 2007-02-18 Igor Zelmanovich * WebUIValidation_2.0.js: diff --git a/mcs/class/System.Web/resources/webform.js b/mcs/class/System.Web/resources/webform.js index 89f80209660..b93791f0db7 100644 --- a/mcs/class/System.Web/resources/webform.js +++ b/mcs/class/System.Web/resources/webform.js @@ -108,10 +108,28 @@ function WebForm_ReEnableControls (currForm) } } -function WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg) +// This function is only used in the context of TARGET_J2EE for portlets +function PortalWebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg, currForm) { - var currForm = WebForm_GetFormFromCtrl (id); - + if (url != null) { + currForm = WebForm_GetFormFromCtrl (id, currForm); + if (url.indexOf ("vmw.action.page=") == 0) { + currForm.__NEXTVMWACTIONPAGE.value = url.substring ("vmw.action.page=".length); + url = currForm.action; + } + else if (url.indexOf ("vmw.render.page=") == 0) + { + currForm.__NEXTVMWRENDERPAGE.value = url.substring ("vmw.render.page=".length); + currForm.submit (); + return; + } + } + return WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg, currForm); +} +function WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg, currForm) +{ + currForm = WebForm_GetFormFromCtrl (id, currForm); + if (typeof(SetValidatorContext) == "function") SetValidatorContext (currForm); @@ -119,24 +137,22 @@ function WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg) if (pval && typeof(Page_ClientValidate) == "function") validationResult = Page_ClientValidate(vg); - if (validationResult) { - if (url != null) - currForm.action = url; - } + if (validationResult && url != null) + currForm.action = url; if (csubm) currForm.__doPostBack (id, par); } -function WebForm_DoCallback (id, arg, callback, ctx, errorCallback) +function WebForm_DoCallback (id, arg, callback, ctx, errorCallback, currForm) { - var currForm = WebForm_GetFormFromCtrl (id); + currForm = WebForm_GetFormFromCtrl (id, currForm); var qs = WebForm_getFormData (currForm) + "__CALLBACKTARGET=" + id + "&__CALLBACKARGUMENT=" + encodeURIComponent(arg); if (currForm["__EVENTVALIDATION"]) qs += "&__EVENTVALIDATION=" + encodeURIComponent(currForm["__EVENTVALIDATION"].value); - WebForm_httpPost (document.URL, qs, function (httpPost) { WebForm_ClientCallback (httpPost, ctx, callback, errorCallback); }); + WebForm_httpPost (currForm.serverURL || document.URL, qs, function (httpPost) { WebForm_ClientCallback (httpPost, ctx, callback, errorCallback, currForm); }); } -function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback) +function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback, currForm) { var doc = httpPost.responseText; if (doc.charAt(0) == "e") { @@ -149,12 +165,12 @@ function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback) if (!isNaN(validationFieldLength)) { var validationField = doc.substring(separatorIndex + 1, separatorIndex + validationFieldLength + 1); if (validationField != "") { - var validationFieldElement = theForm["__EVENTVALIDATION"]; + var validationFieldElement = currForm["__EVENTVALIDATION"]; if (!validationFieldElement) { validationFieldElement = document.createElement("INPUT"); validationFieldElement.type = "hidden"; validationFieldElement.name = "__EVENTVALIDATION"; - theForm.appendChild(validationFieldElement); + currForm.appendChild(validationFieldElement); } validationFieldElement.value = validationField; } @@ -228,8 +244,11 @@ function WebForm_httpPost (url, data, callback) setTimeout (function () { httpPost.send (data); }, 10); } -function WebForm_GetFormFromCtrl (id) +function WebForm_GetFormFromCtrl (id, currForm) { + if (currForm) + return currForm; + // We need to translate the id from ASPX UniqueID to its ClientID. var ctrl = WebForm_GetElementById (id.replace(/\$/g, "_")); while (ctrl != null) {