Quellcode durchsuchen

for TARGET_J2EE only:
implement integration with JSF.

svn path=/trunk/mcs/; revision=91823

Igor Zelmanovich vor 18 Jahren
Ursprung
Commit
c7166273ee

+ 37 - 0
mcs/class/System.Web/System.Web.Phantom/Stubs.cs

@@ -0,0 +1,37 @@
+//
+// (C) 2007 Mainsoft Corporation (http://www.mainsoft.com)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+using System.Web;
+namespace System.Web.J2EE
+{
+	public class PageMapper
+	{
+		public static Type GetObjectType (HttpContext context, string url) {
+			return null;
+			//throw new InvalidOperationException ();
+		}
+	}
+}

+ 72 - 0
mcs/class/System.Web/System.Web.Phantom/System.Web.Phantom.csproj

@@ -0,0 +1,72 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug_Java</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.50727</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{FBFDAD51-74B6-4660-81C0-9C8B6C8D3B47}</ProjectGuid>
+    <ProjectTypeGuids>{F6B19D50-1E2E-4e87-ADFB-10393B439DE0};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <AssemblyName>System.Web.Phantom</AssemblyName>
+    <JDKName>1.6</JDKName>
+    <GHProjectType>1</GHProjectType>
+    <Version>2.0</Version>
+    <UseVSHostingProcess>false</UseVSHostingProcess>
+    <AdditionalClassPath>
+    </AdditionalClassPath>
+    <RootNamespace>System.Web.Phantom</RootNamespace>
+    <jarserver>ipa</jarserver>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Java|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug_Java\</OutputPath>
+    <DefineConstants>DEBUG;TRACE;JAVA</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <BaseAddress>285212672</BaseAddress>
+    <SkipValidation>false</SkipValidation>
+    <KeepIntermediate>false</KeepIntermediate>
+    <TargetPlatform>0</TargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Java|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release_Java\</OutputPath>
+    <DefineConstants>TRACE;JAVA</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <BaseAddress>285212672</BaseAddress>
+    <SkipValidation>false</SkipValidation>
+    <KeepIntermediate>false</KeepIntermediate>
+    <TargetPlatform>0</TargetPlatform>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="..\System.Web\IHttpExtendedHandler.cs">
+      <Link>IHttpExtendedHandler.cs</Link>
+    </Compile>
+    <Compile Include="Stubs.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Include="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
+    <Reference Include="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86" />
+    <Reference Include="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=x86" />
+    <Reference Include="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.csharp.targets" />
+  <Import Project="$(VMW_HOME)\bin\Mainsoft.Common.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+  <ProjectExtensions>
+    <VisualStudio>
+      <UserProperties REFS-RefInfo-system-web="repository:vmw:framework:2.0" REFS-JarPath-system-web="" REFS-RefInfo-rt="repository:jre:sun:1.6.0" REFS-JarPath-rt="" REFS-RefInfo-system-xml="repository:vmw:framework:2.0" REFS-JarPath-system-xml="" REFS-RefInfo-system-data="repository:vmw:framework:2.0" REFS-JarPath-system-data="" REFS-RefInfo-system="repository:vmw:framework:2.0" REFS-JarPath-system="" />
+    </VisualStudio>
+  </ProjectExtensions>
+</Project>

+ 6 - 7
mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlForm.cs

@@ -258,13 +258,12 @@ namespace System.Web.UI.HtmlControls
 			action += Page.Request.QueryStringRaw;
 #if TARGET_J2EE
 			// Allow the page to transform action to a portlet action url
-			if (Page.IsPortletRender) {
-				string customAction = Attributes ["action"];
-				if (customAction != null && customAction.Length > 0)
-					action = customAction;
-				else
-					action = Page.RenderResponse.createActionURL (action);
-			}
+			string customAction = Attributes ["action"];
+			if (String.IsNullOrEmpty(customAction))
+				action = CreateActionUrl (action);
+			else
+				action = customAction;
+
 #endif
 
 #if NET_2_0

+ 2 - 2
mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs

@@ -45,7 +45,7 @@ using System.Globalization;
 namespace System.Web.UI
 {
 	#if NET_2_0
-	public sealed
+	public sealed partial
 	#else
 	internal
 	#endif
@@ -161,7 +161,7 @@ namespace System.Web.UI
 				prefix += page.theForm + ".";
 #if TARGET_J2EE
 			// Allow the page to transform ActionUrl to a portlet action url
-			if (actionUrl != null && page.PortletNamespace != null) {
+			if (actionUrl != null) {
 				actionUrl = page.CreateActionUrl(actionUrl);
 				prefix += "Portal";
 			}

+ 40 - 0
mcs/class/System.Web/System.Web.UI/ClientScriptManager.jvm.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Web.UI;
+using System.Collections.Specialized;
+using System.Collections;
+
+namespace System.Web.UI
+{
+	partial class ClientScriptManager : IStateManager
+	{
+		#region IStateManager Members
+
+		void IStateManager.LoadViewState (object state) {
+			throw new NotSupportedException ();
+		}
+
+		object IStateManager.SaveViewState () {
+			if (hiddenFields != null) {
+				Hashtable clone = (Hashtable) hiddenFields.Clone ();
+				clone.Remove ("__VIEWSTATE");
+				clone.Remove (Page.postEventArgumentID);
+				clone.Remove (Page.postEventSourceID);
+				clone.Remove (Page.CallbackArgumentID);
+				clone.Remove (Page.CallbackSourceID);
+			}
+			return null;
+		}
+
+		void IStateManager.TrackViewState () {
+			throw new NotSupportedException ();
+		}
+
+		bool IStateManager.IsTrackingViewState {
+			get { throw new NotSupportedException (); }
+		}
+
+		#endregion
+	}
+}

+ 29 - 15
mcs/class/System.Web/System.Web.UI/Control.cs

@@ -453,14 +453,12 @@ namespace System.Web.UI
 				EnsureIDInternal ();
 
 				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;
+#if TARGET_J2EE
+					if (getFacesContext () != null)
+						uniqueID = getFacesContext ().getExternalContext ().encodeNamespace (uniqueID);
+#endif
 					return uniqueID;
 				}
 
@@ -825,10 +823,6 @@ namespace System.Web.UI
 
 		Control LookForControlByName (string id)
 		{
-#if TARGET_J2EE
-			if (this == Page && id != null && id == Page.PortletNamespace)
-				return this;
-#endif
 			EnsureControlsCache ();
 			return (Control) _controlsCache [id];
 		}
@@ -1305,17 +1299,37 @@ namespace System.Web.UI
 #endif
 		string ResolveClientUrl (string relativeUrl)
 		{
-#if TARGET_J2EE
-			// There are no relative paths when rendering a J2EE portlet
-			if (Page != null && Page.PortletNamespace != null)
-				return ResolveUrl (relativeUrl);
-#endif
 			if (relativeUrl == null)
 				throw new ArgumentNullException ("relativeUrl");
 
 			if (relativeUrl.Length == 0)
 				return String.Empty;
 
+#if TARGET_J2EE
+			relativeUrl = ResolveClientUrlInternal (relativeUrl);
+
+			javax.faces.context.FacesContext faces = getFacesContext ();
+			if (faces == null)
+				return relativeUrl;
+
+			string url;
+			if (relativeUrl.IndexOf (':') >= 0)
+				url = ResolveAppRelativeFromFullPath (relativeUrl);
+			else if (VirtualPathUtility.IsAbsolute (relativeUrl))
+				url = VirtualPathUtility.ToAppRelative (relativeUrl);
+			else
+				return faces.getApplication ().getViewHandler ().getResourceURL (faces, relativeUrl);
+
+			if (VirtualPathUtility.IsAppRelative (url)) {
+				url = url.Substring (1);
+				url = url.Length == 0 ? "/" : url;
+				return faces.getApplication ().getViewHandler ().getResourceURL (faces, url);
+			}
+			return relativeUrl;
+		}
+		
+		string ResolveClientUrlInternal (string relativeUrl) {
+#endif
 			if (VirtualPathUtility.IsAbsolute (relativeUrl) || relativeUrl.IndexOf (':') >= 0)
 				return relativeUrl;
 

+ 227 - 15
mcs/class/System.Web/System.Web.UI/Control.jvm.cs

@@ -28,14 +28,207 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using [email protected];
 using System.Web.Hosting;
 using System.Text;
+using javax.faces.component;
+using java.util;
+using javax.faces.el;
+using javax.faces.@event;
+using javax.faces.context;
 
 namespace System.Web.UI
 {
-	public partial class Control
+	public partial class Control : UIComponent, StateHolder
 	{
+		ComponentChildrenList _childrenList;
+
+		protected override void addFacesListener (FacesListener __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void broadcast (FacesEvent __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void decode (FacesContext context) {
+			// do nothing
+		}
+
+		public override void encodeBegin (FacesContext __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void encodeChildren (FacesContext __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void encodeEnd (FacesContext __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override UIComponent findComponent (string __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override Map getAttributes () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override int getChildCount () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override List getChildren () {
+			if (_childrenList == null)
+				_childrenList = new ComponentChildrenList (this);
+			return _childrenList;
+		}
+
+		public override string getClientId (FacesContext __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		protected override FacesContext getFacesContext () {
+			return FacesContext.getCurrentInstance ();
+		}
+
+		protected override FacesListener [] getFacesListeners (java.lang.Class __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override UIComponent getFacet (string __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override Map getFacets () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override Iterator getFacetsAndChildren () {
+			// TODO: consider facets.
+			return getChildren ().iterator ();
+		}
+
+		public override string getFamily () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override string getId () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override UIComponent getParent () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		protected override javax.faces.render.Renderer getRenderer (FacesContext __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override string getRendererType () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override bool getRendersChildren () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override ValueBinding getValueBinding (string name) {
+			return null;
+		}
+
+		public override bool isRendered () {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		// TODO: implement
+		public override void processDecodes (FacesContext context) {
+			// call processDecodes for all jsf children
+		}
+
+		public override void processRestoreState (FacesContext context, object state) {
+			throw new NotSupportedException ();
+		}
+
+		public override object processSaveState (FacesContext context) {
+			throw new NotSupportedException ();
+		}
+
+		// TODO: implement
+		public override void processUpdates (FacesContext context) {
+			// call processUpdates for all jsf children
+		}
+
+		// TODO: implement
+		public override void processValidators (FacesContext context) {
+			// call processValidators for all jsf children
+		}
+
+		public override void queueEvent (FacesEvent __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		protected override void removeFacesListener (FacesListener __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void setId (string __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void setParent (UIComponent __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void setRendered (bool __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void setRendererType (string __p1) {
+			throw new Exception ("The method or operation is not implemented.");
+		}
+
+		public override void setValueBinding (string name, ValueBinding binding) {
+			throw new NotSupportedException ();
+		}
+
+		#region StateHolder Members
+
+		bool StateHolder.isTransient () {
+			return !EnableViewState;
+		}
+
+		void StateHolder.restoreState (FacesContext context, object state) {
+			LoadViewState (state);
+		}
+
+		object StateHolder.saveState (FacesContext context) {
+			return SaveViewState ();
+		}
+
+		void StateHolder.setTransient (bool newTransientValue) {
+			EnableViewState = !newTransientValue;
+		}
+
+		#endregion
+
+		class ComponentChildrenList : AbstractList
+		{
+			Control _owner;
+
+			public ComponentChildrenList (Control owner) {
+				_owner = owner;
+			}
+
+			public override object get (int index) {
+				return _owner.Controls [index];
+			}
+
+			public override int size () {
+				return _owner.Controls.Count;
+			}
+		}
+
 		public virtual string TemplateSourceDirectory
 		{
 			get
@@ -52,22 +245,41 @@ namespace System.Web.UI
 			}
 		}
 
+		string ResolveAppRelativeFromFullPath (string url) {
+			Uri uri = new Uri (url);
+			if (String.Compare (uri.Scheme, Page.Request.Url.Scheme, StringComparison.OrdinalIgnoreCase) == 0 &&
+				String.Compare (uri.Host, Page.Request.Url.Host, StringComparison.OrdinalIgnoreCase) == 0 &&
+				uri.Port == Page.Request.Url.Port)
+				return VirtualPathUtility.ToAppRelative (uri.PathAndQuery);
+			return url;
+		}
 
-		// Add a variant for specifying use of portlet resolveRenderUrl
-		internal string ResolveUrl (string relativeUrl, bool usePortletRenderResolve)
-		{
-			relativeUrl = ResolveUrl (relativeUrl);
-			if (usePortletRenderResolve && Page != null)
-				relativeUrl = Page.CreateRenderUrl (relativeUrl);
-			return relativeUrl;
+		internal string CreateActionUrl (string url) {
+			FacesContext faces = getFacesContext ();
+			if (faces == null)
+				return url;
+
+			url = Asp2Jsf (url);
+
+			return faces.getApplication ().getViewHandler ().getActionURL (faces, url);
 		}
 
-		internal string ResolveClientUrl (string relativeUrl, bool usePortletRenderResolve)
-		{
-			relativeUrl = ResolveClientUrl (relativeUrl);
-			if (usePortletRenderResolve && Page != null)
-				relativeUrl = Page.CreateRenderUrl (relativeUrl);
-			return relativeUrl;
+		string Asp2Jsf (string url) {
+			if (VirtualPathUtility.IsAbsolute (url))
+				url = VirtualPathUtility.ToAppRelative (url);
+
+			if (VirtualPathUtility.IsAppRelative (url)) {
+				url = url.Substring (1);
+				return url.Length == 0 ? "/" : url;
+			}
+			return url;
+		}
+
+		internal string ResolveClientUrl (string relativeUrl, bool usePortletRenderResolve) {
+			if (usePortletRenderResolve)
+				return ResolveClientUrl (relativeUrl);
+			else
+				return ResolveUrl (relativeUrl);
 		}
 	}
 }

+ 101 - 28
mcs/class/System.Web/System.Web.UI/Page.cs

@@ -707,7 +707,7 @@ public partial class Page : TemplateControl, IHttpHandler
 		CultureInfo ret = null;
 		if (culture.StartsWith ("auto", StringComparison.InvariantCultureIgnoreCase)) {
 #if TARGET_J2EE
-			if (Context.IsPortletRequest)
+			if (Context.ServletRequest == null)
 				return deflt;
 #endif
 			string[] languages = Request.UserLanguages;
@@ -766,10 +766,6 @@ public partial class Page : TemplateControl, IHttpHandler
 		NameValueCollection coll = null;
 		if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture))
 			coll = req.Form;
-#if TARGET_J2EE
-		else if (IsPortletRender && req.Form ["__VIEWSTATE"] != null)
-			coll = req.Form;
-#endif
 		else
 			coll = req.QueryString;
 
@@ -782,7 +778,17 @@ public partial class Page : TemplateControl, IHttpHandler
 
 		if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
 			return null;
-
+#if TARGET_J2EE
+		if (getFacesContext () != null && _context.Handler != _context.CurrentHandler) {
+			// check if it is PreviousPage
+			string prevViewId = coll [PreviousPageID];
+			if (!String.IsNullOrEmpty (prevViewId)) {
+				string appPath = VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
+				prevViewId = prevViewId.Substring (appPath.Length);
+				isCrossPagePostBack = String.Compare (prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), StringComparison.OrdinalIgnoreCase) == 0;
+			}
+		}
+#endif
 		return coll;
 	}
 
@@ -795,6 +801,14 @@ public partial class Page : TemplateControl, IHttpHandler
 	}
 #endif
 
+	Control FindControl (string id, bool decode) {
+#if TARGET_J2EE
+		if (decode)
+			id = DecodeNamespace (id);
+#endif
+		return FindControl (id);
+	}
+
 #if NET_2_0
 	[Obsolete]
 #endif
@@ -1031,7 +1045,8 @@ public partial class Page : TemplateControl, IHttpHandler
 		writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
 		writer.WriteLine ("\t{0}._instanceVariableName = '{0}';", theForm);
 #if TARGET_J2EE
-		string serverUrl = Context.ServletResponse.encodeURL (Request.RawUrl);
+		// TODO implement callback on portlet
+		string serverUrl = Request.RawUrl;
 		writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl));
 		writer.WriteLine ("\twindow.TARGET_J2EE = true;");
 		writer.WriteLine ("\twindow.IsMultiForm = {0};", IsMultiForm ? "true" : "false");
@@ -1053,6 +1068,18 @@ public partial class Page : TemplateControl, IHttpHandler
 #endif
 
 		if (handleViewState)
+#if TARGET_J2EE
+			if (getFacesContext () != null) {
+				javax.faces.application.ViewHandler viewHandler = getFacesContext ().getApplication ().getViewHandler ();
+				javax.faces.context.ResponseWriter oldFacesWriter = SetupResponseWriter (writer);
+				try {
+					viewHandler.writeState (getFacesContext ());
+				}
+				finally {
+					getFacesContext ().setResponseWriter (oldFacesWriter);
+				}
+			}
+#endif
 			scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
 
 		scriptManager.WriteHiddenFields (writer);
@@ -1113,7 +1140,7 @@ public partial class Page : TemplateControl, IHttpHandler
 
 				used.Add (id, id);
 
-				Control ctrl = FindControl (id);
+				Control ctrl = FindControl (id, true);
 				if (ctrl != null){
 					IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
 					IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
@@ -1145,7 +1172,7 @@ public partial class Page : TemplateControl, IHttpHandler
 		if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
 			string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
 			foreach (string id in handlers) {
-				IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
+				IPostBackDataHandler pbdh = FindControl (id, true) as IPostBackDataHandler;
 				if (pbdh != null) {			
 					_requiresPostBackCopy.Remove (id);
 					if (pbdh.LoadPostData (id, requestValues)) {
@@ -1173,6 +1200,11 @@ public partial class Page : TemplateControl, IHttpHandler
 	public void ProcessRequest (HttpContext context)
 #endif
 	{
+#if TARGET_J2EE
+		if (getFacesContext () != null)
+			EnterThread (context);
+		else
+#endif
 		SetContext (context);
 		
 		if (clientTarget != null)
@@ -1189,6 +1221,16 @@ public partial class Page : TemplateControl, IHttpHandler
 
 		try {
 			InternalProcessRequest ();
+#if TARGET_J2EE
+		} catch (Exception ex) {
+			HandleException (ex);
+			throw;
+		}
+		finally {
+			if (getFacesContext () != null)
+				ExitThread ();
+		}
+#else
 		} catch (ThreadAbortException) {
 			// Do nothing, just ignore it by now.
 		} catch (Exception e) {
@@ -1197,6 +1239,7 @@ public partial class Page : TemplateControl, IHttpHandler
 		} finally {
 			ProcessUnload ();
 		}
+#endif
 	}
 
 	void ProcessException (Exception ex) {
@@ -1213,7 +1256,12 @@ public partial class Page : TemplateControl, IHttpHandler
 				RenderTrace ();
 				UnloadRecursive (true);
 			} catch {}
-
+#if TARGET_J2EE
+			if (getFacesContext () != null) {
+				if(IsCrossPagePostBack)
+					_context.Items [CrossPagePostBack] = this;
+			}
+#endif
 			if (Thread.CurrentThread.CurrentCulture.Equals (_appCulture) == false)
 				Thread.CurrentThread.CurrentCulture = _appCulture;
 
@@ -1332,11 +1380,23 @@ public partial class Page : TemplateControl, IHttpHandler
 			
 		renderingForm = false;	
 
+#if TARGET_J2EE
+		if (getFacesContext () != null)
+			if (IsPostBack || IsCallback)
+				return;
+#endif
+
 		RestorePageState ();
 		ProcessPostData ();
 		ProcessRaiseEvents ();
 		if (ProcessLoadComplete ())
 			return;
+#if TARGET_J2EE
+		if (getFacesContext () != null) {
+			getFacesContext ().renderResponse ();
+			return;
+		}
+#endif
 		RenderPage ();
 	}
 
@@ -1363,9 +1423,6 @@ public partial class Page : TemplateControl, IHttpHandler
 		if (IsPostBack) {
 #endif
 			Trace.Write ("aspx.page", "Begin ProcessPostData");
-#if TARGET_J2EE
-			if (!IsGetBack)
-#endif
 			ProcessPostData (_requestValueCollection, false);
 			Trace.Write ("aspx.page", "End ProcessPostData");
 		}
@@ -1378,9 +1435,6 @@ public partial class Page : TemplateControl, IHttpHandler
 		if (IsPostBack) {
 #endif
 			Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
-#if TARGET_J2EE
-			if (!IsGetBack)
-#endif
 			ProcessPostData (secondPostData, true);
 			Trace.Write ("aspx.page", "End ProcessPostData Second Try");
 		}
@@ -1401,11 +1455,6 @@ public partial class Page : TemplateControl, IHttpHandler
 	void ProcessRaiseEvents () {
 
 #if NET_2_0
-#if TARGET_J2EE
-		if (IsGetBack)
-			RestoreValidatorsState ();
-		else
-#endif
 		if (IsPostBack || IsCallback) {
 #else
 		if (IsPostBack) {
@@ -1430,6 +1479,13 @@ public partial class Page : TemplateControl, IHttpHandler
 			return true;
 
 		if (IsCallback) {
+#if TARGET_J2EE
+			if (getFacesContext () != null) {
+				_callbackTarget = GetCallbackTarget ();
+				ProcessRaiseCallbackEvent (_callbackTarget, ref _callbackEventError);
+				return true;
+			}
+#endif
 			string result = ProcessCallbackData ();
 			HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
 			callbackOutput.Write (result);
@@ -1458,10 +1514,6 @@ public partial class Page : TemplateControl, IHttpHandler
 		Trace.Write ("aspx.page", "Begin SaveStateComplete");
 		OnSaveStateComplete (EventArgs.Empty);
 		Trace.Write ("aspx.page", "End SaveStateComplete");
-#if TARGET_J2EE
-		if (OnSaveStateCompleteForPortlet ())
-			return true;
-#endif // TARGET_J2EE
 #endif // NET_2_0
 		return false;
 	}
@@ -1474,6 +1526,10 @@ public partial class Page : TemplateControl, IHttpHandler
 		//--
 		Trace.Write ("aspx.page", "Begin Render");
 		HtmlTextWriter output = new HtmlTextWriter (Response.Output);
+#if TARGET_J2EE
+		if (getFacesContext () != null)
+			SetupResponseWriter (output);
+#endif
 		RenderControl (output);
 		Trace.Write ("aspx.page", "End Render");
 	}
@@ -1540,7 +1596,7 @@ public partial class Page : TemplateControl, IHttpHandler
                 }
 
 #if NET_2_0
-		targetControl = FindControl (eventTarget);
+		targetControl = FindControl (eventTarget, true);
 		IPostBackEventHandler target = targetControl as IPostBackEventHandler;
 #else
 		IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
@@ -1697,6 +1753,11 @@ public partial class Page : TemplateControl, IHttpHandler
 	PageStatePersister PageStatePersister {
 		get {
 			if (page_state_persister == null)
+#if TARGET_J2EE
+				if (getFacesContext () != null)
+					return new FacesPageStatePersister (this);
+				else
+#endif
 				page_state_persister = new HiddenFieldPageStatePersister (this);
 			return page_state_persister;
 		}
@@ -2057,7 +2118,7 @@ public partial class Page : TemplateControl, IHttpHandler
 		if (callbackTarget == null || callbackTarget.Length == 0)
 			throw new HttpException ("Callback target not provided.");
 
-		Control targetControl = FindControl (callbackTarget);
+		Control targetControl = FindControl (callbackTarget, true);
 		ICallbackEventHandler target = targetControl as ICallbackEventHandler;
 		if (target == null)
 			throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
@@ -2560,10 +2621,22 @@ public partial class Page : TemplateControl, IHttpHandler
 		if (_requestValueCollection != null) {
 			string prevPage = _requestValueCollection [PreviousPageID];
 			if (prevPage != null) {
+#if TARGET_J2EE
+				if (getFacesContext () != null) {
+					IHttpHandler handler = Context.ApplicationInstance.GetHandler (Context, prevPage);
+					Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
+					if (_context.Items.Contains (CrossPagePostBack)) {
+						previousPage = (Page) _context.Items [CrossPagePostBack];
+						_context.Items.Remove (CrossPagePostBack);
+					}
+					return;
+				}
+#else
 				IHttpHandler handler = PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
 				previousPage = (Page) handler;
 				previousPage.isCrossPagePostBack = true;
 				Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
+#endif
 			} 
 		}
 	}
@@ -2627,7 +2700,7 @@ public partial class Page : TemplateControl, IHttpHandler
 
 		foreach (string lss in themes) {
 			HtmlLink hl = new HtmlLink ();
-			hl.Href = ResolveUrl (lss);
+			hl.Href = lss;
 			hl.Attributes["type"] = "text/css";
 			hl.Attributes["rel"] = "stylesheet";
 			Header.Controls.Add (hl);

+ 372 - 178
mcs/class/System.Web/System.Web.UI/Page.jvm.cs

@@ -26,61 +26,62 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using [email protected];
 using javax.servlet.http;
 using System.Collections.Specialized;
 using System.Globalization;
 using System.Web.Hosting;
 using System.Web.J2EE;
-using System.ComponentModel;
+using System.ComponentModel;
+using System.IO;
+using javax.faces.context;
+using javax.faces.render;
+using javax.servlet;
+using javax.faces;
+using javax.faces.application;
+using javax.faces.@event;
+using javax.faces.el;
+using javax.faces.component;
+using System.Threading;
 
 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
-		{
-			get {
-				if (_emptyPortletNamespace)
-					return null;
+	{
+		string _namespace = null;
+		StateManager.SerializedView _facesSerializedView;
+		MethodBinding _action;
+		MethodBinding _actionListener;
+		bool _immediate;
+		Pair _state;
+		bool [] _validatorsState;
+		ICallbackEventHandler _callbackTarget;
+		string _callbackEventError = String.Empty;
+		IHttpHandler _jsfHandler;
+		static readonly object CrossPagePostBack = new object ();
+
+		bool _isMultiForm = false;
+		bool _isMultiFormInited = false;
 
-				if (_PortletNamespace == null) {
-					IPortletResponse portletResponse = null;
-					if (Context != null) {
-						string usePortletNamespace = J2EEUtils.GetInitParameterByHierarchy (Context.Servlet.getServletConfig (), "mainsoft.use.portlet.namespace");
-						if (usePortletNamespace == null || Boolean.Parse(usePortletNamespace))
-							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;
-			}
+		internal string Namespace
+		{
+			get {
+				if (_namespace == null) {
+
+					if (getFacesContext () != null) {
+						_namespace = getFacesContext ().getExternalContext ().encodeNamespace (String.Empty);
+					}
+
+					_namespace = _namespace ?? String.Empty;
+				}
+				return _namespace;
+			}
 		}
 
 		internal string theForm {
 			get {
-				return "theForm" + PortletNamespace;
+				return "theForm" + Namespace;
 			}
 		}
-		
-		bool _isMultiForm = false;
-		bool _isMultiFormInited = false;
 
 		internal bool IsMultiForm {
 			get {
@@ -93,144 +94,337 @@ namespace System.Web.UI
 				}
 				return _isMultiForm;
 			}
-		}
-
-		internal bool IsPortletRender
-		{
-			get {
-				return RenderResponse != null;
-			}
-		}
-
-		internal bool IsGetBack {
-			get {
-				return IsPostBack && IsPortletRender &&
-					(0 == String.Compare (Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase));
-			}
-		}
-
-		internal IPortletRenderResponse RenderResponse
-		{
-			get {
-				if (!_renderResponseInit)
-					if (Context != null) {
-						_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, StringComparison.Ordinal) || url.StartsWith (ActionPageMark, StringComparison.Ordinal))
-				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, StringComparison.InvariantCultureIgnoreCase))
-				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)
-				return false;
-
-			// 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]);
-
-				if (is_validated && Validators.Count > 0) {
-					string validatorsState = GetValidatorsState ();
-#if DEBUG
-					Console.WriteLine ("__VALIDATORSSTATE: " + validatorsState);
-#endif
-					if (!String.IsNullOrEmpty (validatorsState))
-						resp.setRenderParameter ("__VALIDATORSSTATE", validatorsState);
-				}
-			}
-
-			// Stop processing only if we are handling processAction. If we
-			// are handling a postback from render then fall through.
-			return req.processActionOnly ();
-		}
-
-		string GetValidatorsState () {
-			bool [] validatorsState = new bool [Validators.Count];
-			bool isValid = true;
-			for (int i = 0; i < Validators.Count; i++) {
-				IValidator val = Validators [i];
-				if (!val.IsValid)
-					isValid = false;
-				else
-					validatorsState [i] = true;
-			}
-			if (isValid)
-				return null;
-
-			return GetFormatter ().Serialize (validatorsState);
-		}
-
-		void RestoreValidatorsState () {
-			string validatorsStateSerialized = Request.Form ["__VALIDATORSSTATE"];
-			if (String.IsNullOrEmpty (validatorsStateSerialized))
-				return;
-
-			is_validated = true;
-			bool [] validatorsState = (bool []) GetFormatter ().Deserialize (validatorsStateSerialized);
-			for (int i = 0; i < Math.Min (validatorsState.Length, Validators.Count); i++) {
-				IValidator val = Validators [i];
-				val.IsValid = validatorsState [i];
-			}
-		}
+		}
+
+		void EnterThread (HttpContext context) {
+
+			_jsfHandler = context.CurrentHandler;
+			context.PopHandler ();
+			context.PushHandler (this);
+			if (_jsfHandler == context.Handler)
+				context.Handler = this;
+
+			SetContext (context);
+		}
+
+		void ExitThread () {
+			// TODO
+			//if (context.getResponseComplete ())
+			//    Response.End ();
+
+			_context.PopHandler ();
+			_context.PushHandler (_jsfHandler);
+			if (this == _context.Handler)
+				_context.Handler = _jsfHandler;
+
+		}
+
+		public override void encodeBegin (FacesContext context) {
+			// do nothing
+		}
+
+		public override void encodeChildren (FacesContext context) {
+			System.Diagnostics.Trace.WriteLine ("encodeChildren");
+
+			EnterThread (HttpContext.Current);
+			try {
+				if (!context.getResponseComplete ()) {
+
+					if (IsCrossPagePostBack)
+						return;
+
+					if (IsCallback) {
+						string result = ProcessGetCallbackResult (_callbackTarget, _callbackEventError);
+						HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
+						callbackOutput.Write (result);
+						callbackOutput.Flush ();
+						return;
+					}
+
+					// ensure lifecycle complete.
+					if (!IsLoaded) {
+						ProcessLoad ();
+						RestoreValidatorsState (_validatorsState);
+					}
+					if (!IsPrerendered)
+						ProcessLoadComplete ();
+
+					RenderPage ();
+				}
+			}
+			catch (Exception ex) {
+				if (!(ex is ThreadAbortException))
+					ProcessException (ex);
+				throw;
+			}
+			finally {
+				ProcessUnload ();
+				ExitThread ();
+			}
+		}
+
+		public override void encodeEnd (FacesContext context) {
+			// do nothing
+		}
+
+		public override UIComponent getParent () {
+			return null;
+		}
+
+		public override void setParent (UIComponent parent) {
+			//ignore: parent is root
+		}
+
+		// TODO: consider validators state
+		public override object processSaveState (FacesContext context) {
+			System.Diagnostics.Trace.WriteLine ("processSaveState");
+
+			object state = new Pair (_state, GetValidatorsState ());
+			if (getFacesContext ().getApplication ().getStateManager ().isSavingStateInClient (getFacesContext ())) {
+				int length;
+				byte [] buffer = new ObjectStateFormatter (this).SerializeInternal (state, out length);
+				if (buffer.Length != length) {
+					byte [] trimmedBuffer = new byte [length];
+					Array.Copy (buffer, trimmedBuffer, length);
+					buffer = trimmedBuffer;
+				}
+				state = vmw.common.TypeUtils.ToSByteArray (buffer);
+			}
+			return state;
+		}
+
+		public override void processRestoreState (FacesContext context, object state) {
+			System.Diagnostics.Trace.WriteLine ("processRestoreState");
+
+			if (state == null)
+				throw new ArgumentNullException ("state");
+			EnterThread (HttpContext.Current);
+			try {
+				if (getFacesContext ().getApplication ().getStateManager ().isSavingStateInClient (getFacesContext ())) {
+					byte [] buffer = (byte []) vmw.common.TypeUtils.ToByteArray ((sbyte []) state);
+					state = new ObjectStateFormatter (this).DeserializeInternal (buffer);
+				}
+				_state = (Pair) ((Pair) state).First;
+				_validatorsState = (bool []) ((Pair) state).Second;
+				RestorePageState ();
+			}
+			catch (Exception ex) {
+				HandleException (ex);
+				throw;
+			}
+			finally {
+				ExitThread ();
+			}
+		}
+
+		public override void processDecodes (FacesContext context) {
+			System.Diagnostics.Trace.WriteLine ("processDecodes");
+
+			EnterThread (HttpContext.Current);
+			try {
+				ProcessPostData ();
+
+				EventRaiserFacesEvent facesEvent = new EventRaiserFacesEvent (this);
+				facesEvent.setPhaseId (PhaseId.INVOKE_APPLICATION);
+				context.getViewRoot ().queueEvent (facesEvent);
+
+				base.processDecodes (context);
+			}
+			catch (Exception ex) {
+				HandleException (ex);
+				throw;
+			}
+			finally {
+				ExitThread ();
+			}
+		}
+
+		public override void processValidators (FacesContext context) {
+			System.Diagnostics.Trace.WriteLine ("processValidators");
+
+			EnterThread (HttpContext.Current);
+			try {
+				base.processValidators (context);
+			}
+			catch (Exception ex) {
+				HandleException (ex);
+				throw;
+			}
+			finally {
+				ExitThread ();
+			}
+		}
+
+		public override void processUpdates (FacesContext context) {
+			System.Diagnostics.Trace.WriteLine ("processUpdates");
+
+			EnterThread (HttpContext.Current);
+			try {
+				base.processUpdates (context);
+			}
+			catch (Exception ex) {
+				HandleException (ex);
+				throw;
+			}
+			finally {
+				ExitThread ();
+			}
+		}
+
+		public override void broadcast (FacesEvent e) {
+			System.Diagnostics.Trace.WriteLine ("broadcast");
+
+			if (!(e is EventRaiserFacesEvent))
+				throw new NotSupportedException ("FacesEvent of class " + e.GetType ().Name + " not supported by Page");
+
+			EnterThread (HttpContext.Current);
+			try {
+				ProcessRaiseEvents ();
+				ProcessLoadComplete ();
+			}
+			catch (Exception ex) {
+				HandleException (ex);
+				throw;
+			}
+			finally {
+				ExitThread ();
+			}
+		}
+
+		void HandleException (Exception ex) {
+			try {
+				if (!(ex is ThreadAbortException))
+					ProcessException (ex);
+			}
+			finally {
+				ProcessUnload ();
+			}
+		}
+
+		bool [] GetValidatorsState () {
+			if (is_validated && Validators.Count > 0) {
+				bool [] validatorsState = new bool [Validators.Count];
+				bool isValid = true;
+				for (int i = 0; i < Validators.Count; i++) {
+					IValidator val = Validators [i];
+					if (!val.IsValid)
+						isValid = false;
+					else
+						validatorsState [i] = true;
+				}
+				return validatorsState;
+			}
+			return null;
+		}
+
+		void RestoreValidatorsState (bool [] validatorsState) {
+			if (validatorsState == null)
+				return;
+
+			is_validated = true;
+			for (int i = 0; i < Math.Min (validatorsState.Length, Validators.Count); i++) {
+				IValidator val = Validators [i];
+				val.IsValid = validatorsState [i];
+			}
+		}
+
+		ResponseWriter SetupResponseWriter (TextWriter httpWriter) { //TODO
+			FacesContext facesContext = getFacesContext ();
+
+			ResponseWriter oldWriter = facesContext.getResponseWriter ();
+			RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder.getFactory (FactoryFinder.RENDER_KIT_FACTORY);
+			RenderKit renderKit = renderFactory.getRenderKit (facesContext,
+															 facesContext.getViewRoot ().getRenderKitId ());
+
+			ServletResponse response = (ServletResponse) facesContext.getExternalContext ().getResponse ();
+
+			ResponseWriter writer = renderKit.createResponseWriter (new AspNetResponseWriter (httpWriter),
+													 response.getContentType (), //TODO: is this the correct content type?
+													 response.getCharacterEncoding ());
+			facesContext.setResponseWriter (writer);
+
+			return oldWriter;
+		}
+
+		string DecodeNamespace (string id) {
+			if (Namespace.Length > 0 && id.Length > Namespace.Length && id.StartsWith (Namespace, StringComparison.Ordinal))
+				id = id.Substring (Namespace.Length);
+			return id;
+		}
+
+		#region FacesPageStatePersister
+		sealed class FacesPageStatePersister : PageStatePersister
+		{
+			public FacesPageStatePersister (Page page)
+				: base (page) {
+			}
+
+			public override void Load () {
+				if (Page._state != null) {
+					ViewState = Page._state.First;
+					ControlState = Page._state.Second;
+				}
+			}
+
+			public override void Save () {
+				if (ViewState != null || ControlState != null)
+					Page._state = new Pair (ViewState, ControlState);
+			}
+		}
+		#endregion
+
+		#region EventRaiserFacesEvent
+		sealed class EventRaiserFacesEvent : FacesEvent
+		{
+			public EventRaiserFacesEvent (Page page)
+				: base (page) {
+			}
+
+			public override bool isAppropriateListener (FacesListener __p1) {
+				throw new NotSupportedException ();
+			}
+
+			public override void processListener (FacesListener __p1) {
+				throw new NotSupportedException ();
+			}
+		}
+		#endregion
+
+		#region AspNetResponseWriter
+		private sealed class AspNetResponseWriter : java.io.Writer
+		{
+			readonly TextWriter _writer;
+			public AspNetResponseWriter (TextWriter writer) {
+				_writer = writer;
+			}
+			public override void close () {
+				_writer.Close ();
+			}
+
+			public override void flush () {
+				_writer.Flush ();
+			}
+
+			public override void write (char [] __p1, int __p2, int __p3) {
+				_writer.Write (__p1, __p2, __p3);
+			}
+
+			public override void write (int __p1) {
+				_writer.Write ((char) __p1);
+			}
+
+			public override void write (char [] __p1) {
+				_writer.Write (__p1);
+			}
+
+			public override void write (string __p1) {
+				_writer.Write (__p1);
+			}
+
+			public override void write (string __p1, int __p2, int __p3) {
+				_writer.Write (__p1, __p2, __p3);
+			}
+		}
+		#endregion
 	}
 }

+ 20 - 25
mcs/class/System.Web/System.Web/HttpApplication.cs

@@ -77,7 +77,7 @@ using System.Web.SessionState;
 using System.Web.UI;
 
 #if TARGET_J2EE
-using [email protected];
+using Mainsoft.Web;
 #endif
 	
 namespace System.Web {
@@ -702,7 +702,7 @@ namespace System.Web {
 		//
 		// Ticks the clock: next step on the pipeline.
 		//
-		void Tick ()
+		internal void Tick ()
 		{
 			try {
 				if (pipeline.MoveNext ()){
@@ -844,17 +844,6 @@ namespace System.Web {
 			if (error != null){
 				HttpResponse response = context.Response;
 
-#if TARGET_J2EE
-				IPortletActionRequest actionRequest = context.ServletRequest as IPortletActionRequest;
-				IPortletActionResponse actionResponse = context.ServletResponse as IPortletActionResponse;
-				if (actionRequest != null && actionResponse != null && actionRequest.processActionOnly ()) {
-					string exception = "Exception of type " + context.Error.GetType () + 
-						" during processAction: " + context.Error.Message + Console.Out.NewLine + 
-						context.Error.StackTrace;
-					actionResponse.setRenderParameter ("vmw.action.exception", exception);
-					return;
-				}
-#endif
 				if (!response.HeadersSent){
 					response.ClearHeaders ();
 					response.ClearContent ();
@@ -1019,6 +1008,10 @@ namespace System.Web {
 					if (stop)
 						goto release;
 				
+#if TARGET_J2EE
+		processHandler:
+			bool doProcessHandler = false;
+#endif
 			try {
 				context.BeginTimeoutPossible ();
 				if (handler != null){
@@ -1031,6 +1024,10 @@ namespace System.Web {
 					} else {
 						must_yield = false;
 						handler.ProcessRequest (context);
+#if TARGET_J2EE
+						IHttpExtendedHandler extHandler=handler as IHttpExtendedHandler;
+						doProcessHandler = extHandler != null && !extHandler.IsCompleted;
+#endif
 					}
 				}
 			} catch (ThreadAbortException taex){
@@ -1045,6 +1042,12 @@ namespace System.Web {
 				in_begin = false;
 				context.EndTimeoutPossible ();
 			}
+#if TARGET_J2EE
+			if (doProcessHandler) {
+				yield return false;
+				goto processHandler;
+			}
+#endif
 			if (must_yield)
 				yield return stop_processing;
 			else if (stop_processing)
@@ -1291,18 +1294,6 @@ namespace System.Web {
 			
 			begin_iar = new AsyncRequestState (done, cb, extraData);
 
-#if TARGET_J2EE
-			IPortletRenderRequest renderRequest = context.ServletRequest as IPortletRenderRequest;
-			if (renderRequest != null) {
-				string actionException = context.ServletRequest.getParameter ("vmw.action.exception");
-				if (actionException != null && actionException.Length > 0) {
-					FinalErrorWrite (context.Response, actionException.Replace("\n", "<br>"));
-					begin_iar.Complete ();
-					return begin_iar;
-				}
-			}
-#endif
-
 #if TARGET_JVM
 			if (true)
 #else
@@ -1317,6 +1308,10 @@ namespace System.Web {
 
 		void IHttpAsyncHandler.EndProcessRequest (IAsyncResult result)
 		{
+#if TARGET_J2EE
+			if (result == null)
+				result = begin_iar;
+#endif
 			if (!result.IsCompleted)
 				result.AsyncWaitHandle.WaitOne ();
 			begin_iar = null;

+ 4 - 0
mcs/class/System.Web/System.Web/HttpApplicationFactory.cs

@@ -437,6 +437,10 @@ namespace System.Web {
 		//
 		internal static HttpApplication GetApplication (HttpContext context)
 		{
+#if TARGET_J2EE
+			if (context.ApplicationInstance!=null)
+				return context.ApplicationInstance;
+#endif
 			HttpApplicationFactory factory = theFactory;
 			HttpApplication app = null;
 			if (factory.app_start_needed){

+ 17 - 4
mcs/class/System.Web/System.Web/HttpContext.jvm.cs

@@ -32,12 +32,17 @@ using System.Collections;
 using System.Configuration;
 using System.Threading;
 using javax.servlet.http;
-using [email protected];
+using javax.faces.context;
+using System.Web.J2EE;
+using System.Web.UI;
+using javax.servlet;
+using System.Collections.Specialized;
+using Mainsoft.Web;
 
 namespace System.Web {
 	
 	public sealed partial class HttpContext {
-		static LocalDataStoreSlot _ContextSlot = Thread.GetNamedDataSlot ("Context");
+		static readonly LocalDataStoreSlot _ContextSlot = Thread.GetNamedDataSlot ("Context");
 		// No remoting support (CallContext) yet in Grasshopper
 		[MonoInternalNote("Context - Use System.Remoting.Messaging.CallContext instead of Thread storage")]
 		public static HttpContext Current
@@ -61,6 +66,10 @@ namespace System.Web {
 		internal HttpServletRequest ServletRequest {
 			get { return (HttpServletRequest)GetWorkerService(typeof(HttpServletRequest)); }
 		}
+		
+		internal NameValueCollection RequestParameters {
+			get { return (NameValueCollection) GetWorkerService (typeof (NameValueCollection)); }
+		}
 
 		internal HttpServletResponse ServletResponse {
 			get { return (HttpServletResponse)GetWorkerService(typeof(HttpServletResponse)); }
@@ -87,8 +96,6 @@ namespace System.Web {
 			get { return true; }
 		}
 
-		internal bool IsPortletRequest { get { return ServletRequest is IPortletRequest; } }
-
 		internal void BeginTimeoutPossible ()
 		{
 		}
@@ -96,5 +103,11 @@ namespace System.Web {
 		internal void EndTimeoutPossible ()
 		{
 		}
+
+		internal void SetWorkerRequest (HttpWorkerRequest wr) {
+			WorkerRequest = wr;
+			Request.SetWorkerRequest (wr);
+			Response.SetWorkerRequest (wr);
+		}
 	}
 }

+ 1 - 1
mcs/class/System.Web/System.Web/HttpException.cs

@@ -163,7 +163,7 @@ table.sampleCode {{width: 100%; background-color: #ffffcc; }}
 			WriteFileTop (builder, "Runtime Error");
 			builder.Append (@"<p><strong>Description:</strong> An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons)." + (
 #if TARGET_J2EE //on portal we cannot know if we run locally
-				HttpContext.Current.IsPortletRequest ? String.Empty :
+				HttpContext.Current.ServletRequest == null ? String.Empty :
 #endif
 				" It could, however, be viewed by browsers running on the local server machine.") 
 				+ @"</p>

+ 0 - 3
mcs/class/System.Web/System.Web/HttpRequest.cs

@@ -601,9 +601,6 @@ namespace System.Web {
 					if (IsContentType ("multipart/form-data", true))
 						LoadMultiPart ();
 					else if (
-#if TARGET_J2EE
-						Context.IsPortletRequest ||
-#endif
 						IsContentType ("application/x-www-form-urlencoded", true))
 						LoadWwwForm ();
 

+ 16 - 4
mcs/class/System.Web/System.Web/HttpRequest.jvm.cs

@@ -33,7 +33,7 @@ using javax.servlet.http;
 using System.Web.Configuration;
 using System.IO;
 using System.Collections;
-using [email protected];
+using System.Collections.Specialized;
 
 namespace System.Web
 {
@@ -58,7 +58,11 @@ namespace System.Web
 		{
 			HttpServletRequest servletReq = context.ServletRequest;
 			if (servletReq == null) {
-				RawLoadWwwForm ();
+				NameValueCollection requestParameters = context.RequestParameters;
+				if (requestParameters != null)
+					form.Add (requestParameters);
+				else
+					RawLoadWwwForm ();
 				return;
 			}
 
@@ -66,7 +70,7 @@ namespace System.Web
 
 			for (java.util.Enumeration e = servletReq.getParameterNames(); e.hasMoreElements() ;) {
 				string key = (string) e.nextElement();
-				string [] qvalue = Context.IsPortletRequest ? null : QueryString.GetValues (key);
+				string [] qvalue = QueryString.GetValues (key);
 				string [] qfvalue = servletReq.getParameterValues (key);
 
 				for (int i = (qvalue != null) ? qvalue.Length : 0; i < qfvalue.Length; i++)
@@ -178,7 +182,7 @@ namespace System.Web
 			HttpServletRequest servletReq = context.ServletRequest;
 			if (servletReq == null)
 				return;
-			bool inPortletMode = servletReq is IPortletRequest;
+			bool inPortletMode = true; //servletReq is IPortletRequest;
 			bool shouldStoreCookiesCollection = false;
 			HttpSession javaSession = servletReq.getSession(false);
 
@@ -218,5 +222,13 @@ namespace System.Web
 					javaSession.setAttribute (SessionCookies, sessionCookies);
 			}
 		}
+
+		internal void SetWorkerRequest (HttpWorkerRequest wr) {
+			worker_request = wr;
+			current_exe_path = null;
+			file_path = null;
+			base_virtual_dir = null;
+		}
+
 	}
 }

+ 1 - 16
mcs/class/System.Web/System.Web/HttpResponse.cs

@@ -39,15 +39,12 @@ using System.Web.Util;
 using System.Web.Configuration;
 using System.Globalization;
 using System.Security.Permissions;
-#if TARGET_J2EE
-using [email protected];
-#endif
 
 namespace System.Web {
 	
 	// CAS - no InheritanceDemand here as the class is sealed
 	[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
-	public sealed class HttpResponse {
+	public sealed partial class HttpResponse {
 		internal HttpWorkerRequest WorkerRequest;
 		internal HttpResponseStream output_stream;
 		internal bool buffer = true;
@@ -795,18 +792,6 @@ namespace System.Web {
 			if (headers_sent)
 				throw new HttpException ("Headers have already been sent");
 
-#if TARGET_J2EE
-			// In J2EE portal we need to handle Redirect at the processAction phase
-			// using the portlet ActionResponse that will send for us the redirect header.
-			IPortletActionResponse resp = context.ServletResponse as IPortletActionResponse;
-			if (resp != null) {
-				resp.sendRedirect (ApplyAppPathModifier (url));
-				if (endResponse)
-					End ();
-				return;
-			}
-#endif
-
 #if NET_2_0
 			is_request_being_redirected = true;
 #endif

+ 14 - 0
mcs/class/System.Web/System.Web/HttpResponse.jvm.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace System.Web
+{
+	partial class HttpResponse
+	{
+		internal void SetWorkerRequest (HttpWorkerRequest wr) {
+			WorkerRequest = wr;
+		}
+
+	}
+}

+ 24 - 0
mcs/class/System.Web/System.Web/HttpRuntime.cs

@@ -42,6 +42,9 @@ using System.Web.Configuration;
 using System.Web.UI;
 using System.Web.Util;
 using System.Threading;
+#if TARGET_J2EE
+using Mainsoft.Web;
+#endif
 
 #if NET_2_0 && !TARGET_JVM
 using System.CodeDom.Compiler;
@@ -415,7 +418,15 @@ namespace System.Web {
 		
 		static void RealProcessRequest (object o)
 		{
+#if TARGET_J2EE
+			HttpContext context = HttpContext.Current;
+			if (context == null)
+				context = new HttpContext ((HttpWorkerRequest) o);
+			else
+				context.SetWorkerRequest ((HttpWorkerRequest) o);
+#else
 			HttpContext context = new HttpContext ((HttpWorkerRequest) o);
+#endif
 			HttpContext.Current = context;
 			bool error = false;
 #if !TARGET_J2EE
@@ -461,8 +472,21 @@ namespace System.Web {
 				//
 				IHttpAsyncHandler ihah = app;
 
+#if TARGET_J2EE
+				if (context.Handler == null)
+					ihah.BeginProcessRequest (context, new AsyncCallback (request_processed), context);
+				else
+					app.Tick ();
+				//ihh.ProcessRequest (context);
+				IHttpExtendedHandler extHandler = context.Handler as IHttpExtendedHandler;
+				if (extHandler != null && !extHandler.IsCompleted)
+					return;
+
+				ihah.EndProcessRequest (null);
+#else
 				IAsyncResult appiar = ihah.BeginProcessRequest (context, new AsyncCallback (request_processed), context);
 				ihah.EndProcessRequest (appiar);
+#endif
 
 				HttpApplicationFactory.Recycle (app);
 			}

+ 9 - 4
mcs/class/System.Web/System.Web20.csproj

@@ -946,7 +946,6 @@
     <Compile Include="System.Web.UI\OutputCacheLocation.cs" />
     <Compile Include="System.Web.UI\OutputCacheParameters.cs" />
     <Compile Include="System.Web.UI\PageHandlerFactory.cs" />
-    <Compile Include="System.Web.UI\PageLifeCycle.cs" />
     <Compile Include="System.Web.UI\PageStatePersister.cs" />
     <Compile Include="System.Web.UI\PageTheme.cs" />
     <Compile Include="System.Web.UI\Pair.cs" />
@@ -1205,6 +1204,7 @@
     <Compile Include="System.Web.UI.WebControls\XmlBuilder.jvm.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="System.Web.UI\ClientScriptManager.jvm.cs" />
     <Compile Include="System.Web.UI\BaseParser.jvm.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -1269,6 +1269,7 @@
     <Compile Include="System.Web\HttpApplication.cs" />
     <Compile Include="System.Web\HttpCacheVaryByContentEncodings.cs" />
     <Compile Include="System.Web\HttpParamsCollection.cs" />
+    <Compile Include="System.Web\HttpResponse.jvm.cs" />
     <Compile Include="System.Web\HttpResponseStream.jvm.cs" />
     <Compile Include="System.Web\HttpStaticObjectsCollection.cs">
       <SubType>Code</SubType>
@@ -1404,9 +1405,13 @@
     </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
-    <Reference Include="J2EE.Helpers, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
     <Reference Include="J2SE.Helpers, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
     <Reference Include="JavaEE, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
+    <Reference Include="jsf-api, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>Refs\jsf-api.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
     <Reference Include="Mainsoft.Configuration, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
     <Reference Include="rt, Version=1.4.2.65535, Culture=neutral, processorArchitecture=MSIL" />
     <Reference Include="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
@@ -1434,10 +1439,10 @@
   -->
   <ProjectExtensions>
     <VisualStudio>
-      <UserProperties REFS-RefInfo-mainsoft-mscorlib="repository:vmw:framework:2.0" REFS-RefInfo-mainsoft-configuration="repository:vmw:framework:2.0" REFS-JarPath-mainsoft-configuration="" REFS-RefInfo-system-xml="repository:vmw:framework:2.0" REFS-RefInfo-system-drawing="repository:vmw:framework:2.0" REFS-RefInfo-system-data="repository:vmw:framework:2.0" REFS-RefInfo-j2se-helpers="repository:vmw:framework:2.0" REFS-RefInfo-system="repository:vmw:framework:2.0" REFS-RefInfo-system-configuration="repository:vmw:framework:2.0" REFS-RefInfo-j2ee-helpers="repository:vmw:framework:2.0" REFS-RefInfo-javaee="repository:JavaEE:tomcat:1.3" REFS-JarPath-javaee="" REFS-JarPath-j2se-helpers="" REFS-JarPath-j2ee-helpers="" REFS-JarPath-j2ee="..\lib\j2ee.jar" REFS-RefInfo-rt="repository:jre:sun:1.4.2" REFS-JarPath-rt="" REFS-JarPath-mscorlib="" REFS-JarPath-system="" REFS-JarPath-system-xml="" REFS-JarPath-system-drawing="" REFS-JarPath-system-data="" REFS-JarPath-system-configuration="" />
+      <UserProperties REFS-RefInfo-jsf-api="j2il:" REFS-JarPath-jsf-api="..\lib\jsf-api.jar" REFS-JarPath-system-configuration="" REFS-JarPath-system-data="" REFS-JarPath-system-drawing="" REFS-JarPath-system-xml="" REFS-JarPath-system="" REFS-JarPath-mscorlib="" REFS-JarPath-rt="" REFS-RefInfo-rt="repository:jre:sun:1.4.2" REFS-JarPath-j2ee="..\lib\j2ee.jar" REFS-JarPath-j2ee-helpers="" REFS-JarPath-j2se-helpers="" REFS-JarPath-javaee="" REFS-RefInfo-javaee="repository:JavaEE:tomcat:1.3" REFS-RefInfo-j2ee-helpers="repository:vmw:framework:2.0" REFS-RefInfo-system-configuration="repository:vmw:framework:2.0" REFS-RefInfo-system="repository:vmw:framework:2.0" REFS-RefInfo-j2se-helpers="repository:vmw:framework:2.0" REFS-RefInfo-system-data="repository:vmw:framework:2.0" REFS-RefInfo-system-drawing="repository:vmw:framework:2.0" REFS-RefInfo-system-xml="repository:vmw:framework:2.0" REFS-JarPath-mainsoft-configuration="" REFS-RefInfo-mainsoft-configuration="repository:vmw:framework:2.0" REFS-RefInfo-mainsoft-mscorlib="repository:vmw:framework:2.0" />
     </VisualStudio>
   </ProjectExtensions>
   <PropertyGroup>
     <PreBuildEvent>"$(ProjectDir)..\..\class\lib\net_2_0\culevel.exe" -o "$(ProjectDir)System.Web\UplevelHelper.cs" "$(ProjectDir)UplevelHelperDefinitions.xml"</PreBuildEvent>
   </PropertyGroup>
-</Project>
+</Project>