struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject svn commit: r327181 - in /struts/sandbox/trunk/overdrive/Nexus: Core/Helpers/IViewHelper.cs Core/Helpers/ViewHelper.cs Web/AlertLabel.cs Web/FindControl.ascx.cs Web/GridControl.ascx.cs Web/MessageLabel.cs Web/ViewControl.ascx.cs Web/WebHelper.cs
Date Fri, 21 Oct 2005 13:48:04 GMT
Author: husted
Date: Fri Oct 21 06:47:54 2005
New Revision: 327181

URL: http://svn.apache.org/viewcvs?rev=327181&view=rev
Log:
OVR-23
* Add automatic binding for TextLabels
* Rename ErrorsText to AlertsText for consistency
* Add support methods for obtaining messages for an entity ID
* Rename View_Errors to View_Alerts for consistency

Modified:
    struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs
    struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/AlertLabel.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/FindControl.ascx.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/MessageLabel.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs

Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs Fri Oct 21 06:47:54 2005
@@ -88,6 +88,29 @@
 		IDictionary Alerts { get; }
 
 		/// <summary>
+		/// Return the Alerts for the specifiied ID, 
+		/// formatted for display by a UI control.
+		/// </summary>
+		/// <remarks>
+		/// If messages are localized or customized, 
+		/// the helper will return correct version for the user.
+		/// UI specific implementation may markup the errors as needed.
+		/// </remarks>
+		/// 
+		string AlertsFor(string id);
+
+		/// <summary>
+		/// Return the Alerts, including any Fault, formatted for display by a UI control.
+		/// </summary>
+		/// <remarks>
+		/// If messages are localized or customized, 
+		/// the helper will return correct version for the user.
+		/// UI specific implementation may markup the errors as needed.
+		/// </remarks>
+		/// 
+		string AlertsText { get; }
+
+		/// <summary>
 		/// Indicate if alerts are queued.
 		/// </summary>
 		/// <returns>True if alerts are queued.</returns>
@@ -118,7 +141,16 @@
 		bool IsNominal { get; }
 
 		/// <summary>
-		/// Return the Alerts, including any Fault, formatted for display by a UI control.
+		/// Record a list of hint (or advisory) messages, 
+		/// keyed by a field or other identifier, 
+		/// or to a magic global key.
+		/// </summary>
+		/// 
+		IDictionary Hints { get; }
+
+		/// <summary>
+		/// Return the Hints for the specifiied ID, 
+		/// formatted for display by a UI control.
 		/// </summary>
 		/// <remarks>
 		/// If messages are localized or customized, 
@@ -126,15 +158,7 @@
 		/// UI specific implementation may markup the errors as needed.
 		/// </remarks>
 		/// 
-		string ErrorsText { get; }
-
-		/// <summary>
-		/// Record a list of hint (or advisory) messages, 
-		/// keyed by a field or other identifier, 
-		/// or to a magic global key.
-		/// </summary>
-		/// 
-		IDictionary Hints { get; }
+		string HintsFor(string id);
 
 		/// <summary>
 		/// Indicate if Hints are queued.

Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs Fri Oct 21 06:47:54 2005
@@ -147,7 +147,11 @@
 
 		#region Messages (abstract) 
 
-		public abstract string ErrorsText { get; }
+		public abstract string AlertsFor(string id);
+
+		public abstract string AlertsText { get; }
+
+		public abstract string HintsFor(string id);
 
 		public abstract string HintsText { get; }
 

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/AlertLabel.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/AlertLabel.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/AlertLabel.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/AlertLabel.cs Fri Oct 21 06:47:54 2005
@@ -10,18 +10,22 @@
 		/// <summary>
 		/// Default suffix for NameLabel IDs ["_alert"].
 		/// </summary>
+		/// 
 		public const string ALERT_SUFFIX = "_alert";
 		
 		/// <summary>
 		/// Set the defaults for this subclass.
 		/// </summary>
+		/// 
 		public AlertLabel()
 		{
 			Suffix = ALERT_SUFFIX;
 			Resource = false;
 			Required = false;
 			View_Hint = false;
+			EnableViewState = false;
 		}
+
 	}
 }
 

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/FindControl.ascx.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/FindControl.ascx.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/FindControl.ascx.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/FindControl.ascx.cs Fri Oct 21 06:47:54 2005
@@ -42,7 +42,7 @@
 				IViewHelper helper = Read(FindCommand);
 				if (!helper.IsNominal)
 				{
-					Page_Error = helper;
+					Page_Alert = helper;
 				}
 				return helper.Criteria;
 			}
@@ -82,7 +82,7 @@
 		public virtual void Open()
 		{
 			IViewHelper helper = ExecuteBind(FindCommand);
-			if (!helper.IsNominal) Page_Error = helper;
+			if (!helper.IsNominal) Page_Alert = helper;
 		}
 
 		public virtual void Open(IDictionary criteria)
@@ -90,7 +90,7 @@
 			IViewHelper helper = GetHelperFor(FindCommand);
 			helper.Read(criteria, true);
 			ExecuteBind(helper);
-			if (!helper.IsNominal) Page_Error = helper;
+			if (!helper.IsNominal) Page_Alert = helper;
 		}
 
 		/// <summary>

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs Fri Oct 21 06:47:54 2005
@@ -549,7 +549,7 @@
 			bool okay = helper.IsNominal;
 			if (!okay)
 			{
-				Page_Error = helper;
+				Page_Alert = helper;
 			}
 			return okay;
 		}
@@ -641,7 +641,7 @@
 				list_Insert = true;
 				list_ItemIndex = 0;
 			}
-			else Page_Error = helper;
+			else Page_Alert = helper;
 		}
 
 		#endregion
@@ -688,7 +688,7 @@
 				okay = this.Open();
 				// ISSUE: Event? Page_Prompt = (List_Insert) ? msg_ADD_SUCCESS : msg_SAVE_SUCCESS;
 			}
-			if (!okay) Page_Error = helper;
+			if (!okay) Page_Alert = helper;
 		}
 
 		private void list_Quit(object source, DataGridCommandEventArgs e)

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/MessageLabel.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/MessageLabel.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/MessageLabel.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/MessageLabel.cs Fri Oct 21 06:47:54 2005
@@ -1,4 +1,6 @@
+using System;
 using System.Web.UI.WebControls;
+using Nexus.Core.Helpers;
 
 namespace Nexus.Web
 {
@@ -123,6 +125,34 @@
 			set { _View_Alert = value;}
 		}
 
-	}
-		
+		/// <summary>
+		/// Present a list of error mesasges.
+		/// </summary>
+		/// 
+		protected IViewHelper Alerts
+		{
+			set
+			{
+				if (value != null)
+				{
+					Text = value.AlertsFor(EntryID);
+				}
+			}
+		}
+
+		/// <summary>
+		/// Provide a standard Event Handler for passing Alert messages.
+		/// </summary>
+		/// <param name="sender">Event source</param>
+		/// <param name="e">Runtime parameters</param>
+		/// 
+		public void View_Alert_Handler(object sender, EventArgs e)
+		{
+			ViewArgs v = e as ViewArgs;
+			if (v == null) throw new ArgumentException("ViewLabel.View_Alert_Handler: !(e is ViewArgs)");
+			IViewHelper helper = v.Helper;
+			if (helper != null) Alerts = helper;
+			else throw new ArgumentException("ViewLabel.View_Alert_Handler: (e.helper==null)");
+		}
+	}		
 }

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs Fri Oct 21 06:47:54 2005
@@ -34,9 +34,9 @@
 		/// Psuedo property to generate an Error event encapsulating 
 		/// our Helper property, containing the error.
 		/// </summary>
-		protected IViewHelper Page_Error
+		protected IViewHelper Page_Alert
 		{
-			set { View_Error_Handler(this, new ViewArgs(value)); }
+			set { View_Alert_Handler(this, new ViewArgs(value)); }
 		}
 
 		#region String utilities 
@@ -151,7 +151,7 @@
 		/// <param name="control">Control to test.</param>
 		/// <returns>True if control is a NameLabel</returns>
 		/// 
-		protected bool IsMessageLabel(Control control)
+		protected bool IsViewLabel(Control control)
 		{
 			return (control is MessageLabel);
 		}
@@ -327,6 +327,22 @@
 			return helper;
 		}
 
+		protected virtual void InitViewLabels()
+		{
+			foreach (Control t in Controls)
+			{
+				if (IsViewLabel(t))
+				{
+					MessageLabel x = (MessageLabel) t;
+					if (x.View_Alert)
+					{
+						View_Alert += new EventHandler(x.View_Alert_Handler);
+					}
+					continue;
+				}				
+			}			
+		}
+
 		private void BindControls(ControlCollection controls, IDictionary dictionary, string prefix,
string list_suffix)
 		{
 			foreach (Control t in controls)
@@ -337,7 +353,7 @@
 					object v = dictionary[ToColumn(x.ID, prefix)];
 					if (v != null) x.Text = v.ToString();
 				}
-				if (IsMessageLabel(t))
+				if (IsViewLabel(t))
 				{
 					MessageLabel x = (MessageLabel) t;
 					object v = dictionary[ToColumn(x.ID, prefix)];
@@ -560,7 +576,7 @@
 		{
 			foreach (Control t in controls)
 			{
-				if (IsMessageLabel(t))
+				if (IsViewLabel(t))
 				{
 					MessageLabel x = (MessageLabel) t;
 					if (x.Resource) try
@@ -669,29 +685,29 @@
 		/// <summary>
 		/// Signal when an error is exposed. 
 		/// </summary>
-		public event EventHandler View_Error;
+		public event EventHandler View_Alert;
 
 		/// <summary>
 		/// Pass an error to another control registered to received it.
 		/// </summary>
 		/// <param name="sender">This object</param>
 		/// <param name="e">A ViewArgs instance with the IViewHelper containing the error
messages(s).</param>
-		private void View_Error_Handler(object sender, EventArgs e)
+		private void View_Alert_Handler(object sender, EventArgs e)
 		{
-			if (View_Error != null)
+			if (View_Alert != null)
 			{
-				View_Error(sender, e);
+				View_Alert(sender, e);
 			}
 		}
 
 		/// <summary>
-		/// Initialize the control to use the stanard View_Error event handerl.
+		/// Initialize the control to use the standard View_Alert event handerl.
 		/// </summary>
 		/// <param name="c">Control to register</param>
 		/// 
 		protected void InitView(ViewControl c)
 		{
-			c.View_Error += new EventHandler(View_Error_Handler);
+			c.View_Alert += new EventHandler(View_Alert_Handler); // Bubble event
 			c.Profile = Profile;
 		}
 
@@ -723,6 +739,7 @@
 		/// </p></remarks>
 		protected virtual void Page_Init()
 		{
+			InitViewLabels();
 			if (IsPostBack) return;
 			GetMessages();
 		}

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs?rev=327181&r1=327180&r2=327181&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs Fri Oct 21 06:47:54 2005
@@ -6,9 +6,32 @@
 {
 	public class WebHelper : ViewHelper
 	{
-		public override string ErrorsText
+		public override string AlertsFor(string id)
 		{
-			get { return HtmlMessageBuilder(Alerts); }
+			string alert = null;			
+			IList list = Alerts[id] as IList;
+			if (list==null) return alert; 
+
+			if (list.Count==1)
+			{
+				alert = HtmlMessage(list[0]);
+			}
+			else
+			{
+				alert = HtmlMessageList(list);
+			} 
+			return alert;
+		}
+
+		public override string AlertsText
+		{
+			get
+			{	return HtmlMessageBuilder(Alerts); }
+		}
+
+		public override string HintsFor(string id)
+		{
+			 return HtmlMessageList(Hints[id] as IList); 
 		}
 
 		public override string HintsText
@@ -17,6 +40,20 @@
 		}
 
 		#region Message utilities
+
+		/// <summary>
+		/// Build a  message using HTML markup.
+		/// </summary>
+		/// <param name="message">A message</param>
+		/// <returns>HTML markup presenting the messages.</returns>
+		/// 
+		private string HtmlMessage(object message)
+		{
+			StringBuilder sb = new StringBuilder("<p>");
+			sb.Append(message.ToString());
+			sb.Append("</p>");
+			return sb.ToString();
+		}
 
 		/// <summary>
 		/// Build a set of messages using HTML markup.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message