You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2005/09/10 21:13:11 UTC
svn commit: r280027 - in /struts/sandbox/trunk/overdrive/Nexus:
Core/Helpers/IViewHelper.cs Core/Helpers/ViewHelper.cs
Core/IRequestCatalog.cs Extras/Spring/Catalog.cs Test/ControllerTest.cs
Web/GridControl.ascx.cs Web/ViewControl.ascx.cs Web/WebHelper.cs
Author: husted
Date: Sat Sep 10 12:12:59 2005
New Revision: 280027
URL: http://svn.apache.org/viewcvs?rev=280027&view=rev
Log:
OVR-15
* Reformat code only. No changes.
Modified:
struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs
struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs
struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs
struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.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=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs Sat Sep 10 12:12:59 2005
@@ -33,9 +33,8 @@
///
public interface IViewHelper
{
-
#region "Deprecated" in favor of new ViewControl methods
-
+
/// <summary>
/// Invoke the helper's command and bind the output to
/// controls in the given collection.
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=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs Sat Sep 10 12:12:59 2005
@@ -26,7 +26,6 @@
///
public abstract class ViewHelper : IViewHelper
{
-
/// <summary>
/// Default setting for ListSuffix ["_list"].
/// </summary>
@@ -76,22 +75,22 @@
public void Read(IDictionary input, bool nullIfEmpty)
{
- if (input==null) return;
+ if (input == null) return;
ICollection keys = input.Keys;
IDictionary criteria = Criteria;
if (nullIfEmpty)
foreach (string key in keys)
- {
- object value = input[key];
- string s = value as string;
- if ((s!=null) && (s.Length==0))
- criteria.Add(key,null);
- else
- criteria.Add(key,value);
- }
+ {
+ object value = input[key];
+ string s = value as string;
+ if ((s != null) && (s.Length == 0))
+ criteria.Add(key, null);
+ else
+ criteria.Add(key, value);
+ }
else foreach (string key in keys)
{
- criteria.Add(key,input[key]);
+ criteria.Add(key, input[key]);
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs?rev=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs Sat Sep 10 12:12:59 2005
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-using System;
using System.Collections;
using Agility.Core;
using Nexus.Core.Helpers;
@@ -80,7 +79,7 @@
/// </summary>
/// <param name="command">The Command ID</param>
/// <returns>Helper instance for command</returns>
- IViewHelper GetHelperFor(string command);
+ IViewHelper GetHelperFor(string command);
/// <summary>
/// Obtain Command and verify that instance is a IRequestCommand.
Modified: struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs?rev=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs Sat Sep 10 12:12:59 2005
@@ -95,7 +95,8 @@
return o as ICommand;
}
- public IRequestCommand GetRequestCommand(string name) {
+ public IRequestCommand GetRequestCommand(string name)
+ {
ICommand c = GetCommand(name);
IRequestCommand command = c as IRequestCommand;
if (command == null)
Modified: struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs?rev=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs Sat Sep 10 12:12:59 2005
@@ -18,7 +18,6 @@
namespace Nexus.Core
{
-
/// <summary>
/// Exercise IRequestCatalog per [OVR-8].
/// </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=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/GridControl.ascx.cs Sat Sep 10 12:12:59 2005
@@ -430,14 +430,14 @@
list_Item_Click(index);
break;
default:
- {
- if (list_Insert)
- // ISSUE: If insert fails, old input is not retained. [WNE-67]
- list_Add_Load();
- else
- list_Refresh();
- break;
- }
+ {
+ if (list_Insert)
+ // ISSUE: If insert fails, old input is not retained. [WNE-67]
+ list_Add_Load();
+ else
+ list_Refresh();
+ break;
+ }
}
}
@@ -478,34 +478,34 @@
#region List events
- private string GetDataKey ()
+ private string GetDataKey()
{
DataGrid grid = Grid;
int index = grid.EditItemIndex;
- string key = grid.DataKeys [index] as string;
+ string key = grid.DataKeys[index] as string;
return key;
}
- private ControlCollection GetControls (DataGridCommandEventArgs e)
+ private ControlCollection GetControls(DataGridCommandEventArgs e)
{
DataGrid grid = Grid;
- ControlCollection controls = new ControlCollection (grid);
+ ControlCollection controls = new ControlCollection(grid);
foreach (TableCell t in e.Item.Cells)
{
for (int i = 0; i < t.Controls.Count; i++)
- controls.Add (t.Controls [i]);
+ controls.Add(t.Controls[i]);
}
return controls;
}
- private bool GetList ()
+ private bool GetList()
{
- IViewHelper helper = Execute (ListCommand);
+ IViewHelper helper = Execute(ListCommand);
bool okay = helper.IsNominal;
if (okay)
{
- DataSource (helper);
- DataBind ();
+ DataSource(helper);
+ DataBind();
}
return okay;
}
@@ -518,7 +518,7 @@
}
protected void list_Save(object source, DataGridCommandEventArgs e)
- {
+ {
string key = (list_Insert) ? null : GetDataKey();
ControlCollection controls = GetControls(e);
IViewHelper helper = Save(key, controls);
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=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/ViewControl.ascx.cs Sat Sep 10 12:12:59 2005
@@ -6,572 +6,573 @@
using Nexus.Core.Helpers;
using UserControl = Spring.Web.UI.UserControl;
-namespace Nexus.Web.Controls
+namespace Nexus.Web.Controls
{
/// <summary>
/// Base class for view controls (sub forms).
/// </summary>
public class ViewControl : UserControl
{
- private string _TitleText;
- public virtual string TitleText
- {
- get { return _TitleText; }
- set { _TitleText = value; }
- }
+ private string _TitleText;
- private string _HeadingText;
- public virtual string HeadingText
- {
- get { return _HeadingText; }
- set { _HeadingText = value; }
- }
+ public virtual string TitleText
+ {
+ get { return _TitleText; }
+ set { _TitleText = value; }
+ }
- private string _PromptText;
- public virtual string PromptText
- {
- get { return _PromptText; }
- set { _PromptText = value; }
- }
-
- private IRequestCatalog _Catalog;
-
- /// <summary>
- /// Helper passed by an enclosing control (e.g. Page).
- /// </summary>
- /// <remarks><p>
- /// Subclasses adding EventHandlers
- /// should pass a reference to themselves with a ViewArgs instance,
- /// encapsulating the Helper.
- /// </p></remarks>
- public virtual IRequestCatalog Catalog
- {
- get { return _Catalog; }
- set { _Catalog = value; }
- }
+ private string _HeadingText;
- /// <summary>
- /// Psuedo property to generate an Error event encapsulating
- /// our Helper property, containing the error.
- /// </summary>
- protected IViewHelper Page_Error
- {
- set { View_Error_Send(this, new ViewArgs(value)); }
- }
+ public virtual string HeadingText
+ {
+ get { return _HeadingText; }
+ set { _HeadingText = value; }
+ }
- #region Control utilities
+ private string _PromptText;
- #region String utilities
+ public virtual string PromptText
+ {
+ get { return _PromptText; }
+ set { _PromptText = value; }
+ }
- private string NullIfEmpty(string input)
- {
- return (string.Empty.Equals(input)) ? null : input;
- }
+ private IRequestCatalog _Catalog;
- /// <summary>
- /// Extract the root name from the id, allowing for a prefix and suffix.
- /// </summary>
- /// <param name="id">The full id, including prefix and suffix.</param>
- /// <param name="prefix">The prefix to omit.</param>
- /// <param name="suffix">The suffix to omit.</param>
- /// <returns></returns>
- private string RootId(string id, string prefix, string suffix)
- {
- int v = id.LastIndexOf(suffix);
- string fore = id.Substring(0, v);
- string root = ToColumn(fore, prefix);
- return root;
- }
+ /// <summary>
+ /// Helper passed by an enclosing control (e.g. Page).
+ /// </summary>
+ /// <remarks><p>
+ /// Subclasses adding EventHandlers
+ /// should pass a reference to themselves with a ViewArgs instance,
+ /// encapsulating the Helper.
+ /// </p></remarks>
+ public virtual IRequestCatalog Catalog
+ {
+ get { return _Catalog; }
+ set { _Catalog = value; }
+ }
- /// <summary>
- /// Trim Sany QL wildcards that may have been added to a search string.
- /// </summary>
- /// <param name="input">String to trim</param>
- /// <returns>Input without SQL wildcards</returns>
- protected string TrimWildCards(string input)
- {
- string trimmed = null;
- if (input!=null) trimmed = input.Trim('%');
- return trimmed;
- }
+ /// <summary>
+ /// Psuedo property to generate an Error event encapsulating
+ /// our Helper property, containing the error.
+ /// </summary>
+ protected IViewHelper Page_Error
+ {
+ set { View_Error_Send(this, new ViewArgs(value)); }
+ }
- private static KeyValue _NullKey = new KeyValue(String.Empty, "--v--");
+ #region Control utilities
- /// <summary>
- /// Default value for dropdown lists.
- /// </summary>
- protected KeyValue NullKey
- {
- get { return _NullKey; }
- }
+ #region String utilities
- /// <summary>
- /// The default list suffix.
- /// </summary>
- private string _ListSuffix = "_list";
+ private string NullIfEmpty(string input)
+ {
+ return (string.Empty.Equals(input)) ? null : input;
+ }
- protected string ListSuffix
- {
- get { return _ListSuffix; }
- set { _ListSuffix = value; }
- }
+ /// <summary>
+ /// Extract the root name from the id, allowing for a prefix and suffix.
+ /// </summary>
+ /// <param name="id">The full id, including prefix and suffix.</param>
+ /// <param name="prefix">The prefix to omit.</param>
+ /// <param name="suffix">The suffix to omit.</param>
+ /// <returns></returns>
+ private string RootId(string id, string prefix, string suffix)
+ {
+ int v = id.LastIndexOf(suffix);
+ string fore = id.Substring(0, v);
+ string root = ToColumn(fore, prefix);
+ return root;
+ }
- #endregion
+ /// <summary>
+ /// Trim Sany QL wildcards that may have been added to a search string.
+ /// </summary>
+ /// <param name="input">String to trim</param>
+ /// <returns>Input without SQL wildcards</returns>
+ protected string TrimWildCards(string input)
+ {
+ string trimmed = null;
+ if (input != null) trimmed = input.Trim('%');
+ return trimmed;
+ }
- /// <summary>
- /// Return true if control is a Label.
- /// </summary>
- /// <param name="control">Control to test.</param>
- /// <returns>True if control is a Label</returns>
- ///
- protected bool IsLabel(Control control)
- {
- return (typeof (Label).Equals(control.GetType()));
- }
+ private static KeyValue _NullKey = new KeyValue(String.Empty, "--v--");
- /// <summary>
- /// Return true if control is a TextBox.
- /// </summary>
- /// <param name="control">Control to test.</param>
- /// <returns>True if control is a TextBox</returns>
- ///
- protected bool IsTextBox(Control control)
- {
- return (typeof (TextBox).Equals(control.GetType()));
- }
+ /// <summary>
+ /// Default value for dropdown lists.
+ /// </summary>
+ protected KeyValue NullKey
+ {
+ get { return _NullKey; }
+ }
- /// <summary>
- /// Return true if control is a List Control or one of the standard subclasses.
- /// </summary>
- /// <param name="control">Control to test.</param>
- /// <returns>True if control is a TextBox</returns>
- ///
- protected bool IsListControl(Control control)
- {
- bool isList = false;
- Type type = control.GetType();
- isList = (isList) || typeof (ListControl).Equals(type);
- isList = (isList) || typeof (CheckBoxList).Equals(type);
- isList = (isList) || typeof (DropDownList).Equals(type);
- isList = (isList) || typeof (ListBox).Equals(type);
- isList = (isList) || typeof (RadioButtonList).Equals(type);
- return isList;
- }
+ /// <summary>
+ /// The default list suffix.
+ /// </summary>
+ private string _ListSuffix = "_list";
+
+ protected string ListSuffix
+ {
+ get { return _ListSuffix; }
+ set { _ListSuffix = value; }
+ }
- /// <summary>
- /// Return true if control is a Checkbox.
- /// </summary>
- /// <param name="control">Control to test.</param>
- /// <returns>True if control is a Checkbox</returns>
- ///
- protected bool IsCheckBox(Control control)
- {
- return (typeof (CheckBox).Equals(control.GetType()));
- }
+ #endregion
- /// <summary>
- /// Return true if control is a RadioButton.
- /// </summary>
- /// <param name="control">Control to test.</param>
- /// <returns>True if control is a RadioButton</returns>
- ///
- protected bool IsRadioButton(Control control)
- {
- return (typeof (RadioButton).Equals(control.GetType()));
- }
+ /// <summary>
+ /// Return true if control is a Label.
+ /// </summary>
+ /// <param name="control">Control to test.</param>
+ /// <returns>True if control is a Label</returns>
+ ///
+ protected bool IsLabel(Control control)
+ {
+ return (typeof (Label).Equals(control.GetType()));
+ }
- /// <summary>
- /// Select only those items in control
- /// whose Text property matches the given text.
- /// If the value is null, no action is taken.
- /// </summary>
- /// <param name="control">Control to set</param>
- /// <param name="text">Text to match</param>
- ///
- protected void SelectItemText(ListControl control, string text)
- {
- if (text != null)
- {
- foreach (ListItem i in control.Items)
- i.Selected = false;
+ /// <summary>
+ /// Return true if control is a TextBox.
+ /// </summary>
+ /// <param name="control">Control to test.</param>
+ /// <returns>True if control is a TextBox</returns>
+ ///
+ protected bool IsTextBox(Control control)
+ {
+ return (typeof (TextBox).Equals(control.GetType()));
+ }
- foreach (ListItem i in control.Items)
- {
- if (text.Equals(i.Text))
- i.Selected = true;
- }
- }
- }
+ /// <summary>
+ /// Return true if control is a List Control or one of the standard subclasses.
+ /// </summary>
+ /// <param name="control">Control to test.</param>
+ /// <returns>True if control is a TextBox</returns>
+ ///
+ protected bool IsListControl(Control control)
+ {
+ bool isList = false;
+ Type type = control.GetType();
+ isList = (isList) || typeof (ListControl).Equals(type);
+ isList = (isList) || typeof (CheckBoxList).Equals(type);
+ isList = (isList) || typeof (DropDownList).Equals(type);
+ isList = (isList) || typeof (ListBox).Equals(type);
+ isList = (isList) || typeof (RadioButtonList).Equals(type);
+ return isList;
+ }
- /// <summary>
- /// Set Labels and TextBoxes to an empty string
- /// to ensure inappropriate values are not carried over.
- /// </summary>
- ///
- protected void ResetControls()
- {
-
- ControlCollection controls = this.Controls;
- foreach (Control control in controls)
- {
- if (IsLabel(control))
- {
- Label x = (Label) control;
- x.Text = String.Empty;
- }
- if (IsTextBox(control))
- {
- TextBox x = (TextBox) control;
- x.Text = String.Empty;
- }
- if (IsListControl(control))
- {
- ListControl x = (ListControl) control;
- x.SelectedIndex = -1;
- }
- }
- }
+ /// <summary>
+ /// Return true if control is a Checkbox.
+ /// </summary>
+ /// <param name="control">Control to test.</param>
+ /// <returns>True if control is a Checkbox</returns>
+ ///
+ protected bool IsCheckBox(Control control)
+ {
+ return (typeof (CheckBox).Equals(control.GetType()));
+ }
- protected IViewHelper GetHelperFor(string command)
- {
- IViewHelper helper = Catalog.GetHelperFor(command);
- return helper;
- }
+ /// <summary>
+ /// Return true if control is a RadioButton.
+ /// </summary>
+ /// <param name="control">Control to test.</param>
+ /// <returns>True if control is a RadioButton</returns>
+ ///
+ protected bool IsRadioButton(Control control)
+ {
+ return (typeof (RadioButton).Equals(control.GetType()));
+ }
- protected IViewHelper Execute(string command)
+ /// <summary>
+ /// Select only those items in control
+ /// whose Text property matches the given text.
+ /// If the value is null, no action is taken.
+ /// </summary>
+ /// <param name="control">Control to set</param>
+ /// <param name="text">Text to match</param>
+ ///
+ protected void SelectItemText(ListControl control, string text)
+ {
+ if (text != null)
{
- IViewHelper helper = GetHelperFor(command);
- helper.Execute();
- return helper;
- }
+ foreach (ListItem i in control.Items)
+ i.Selected = false;
- protected void BindControls(IDictionary dictionary, string prefix, string list_suffix)
- {
- ControlCollection controls = this.Controls;
- foreach (Control t in controls)
- {
- if (IsTextBox(t))
- {
- TextBox x = (TextBox) t;
- object v = dictionary[ToColumn(x.ID, prefix)];
- if (v != null) x.Text = v.ToString();
- }
- if (IsLabel(t))
- {
- Label x = (Label) t;
- object v = dictionary[ToColumn(x.ID, prefix)];
- if (v != null) x.Text = v.ToString();
- }
- if (IsListControl(t))
- {
- ListControl x = (ListControl) t;
- string root = RootId(x.ID, prefix, list_suffix);
- IList s = dictionary[root + list_suffix] as IList; // this_key_list
- string r = dictionary[root] as string; // this_key
- if ((null == r) || (0 == r.Length))
- BindListControl(x, s);
- else
- BindListControl(x, s, r);
- }
+ foreach (ListItem i in control.Items)
+ {
+ if (text.Equals(i.Text))
+ i.Selected = true;
}
}
+ }
- protected void BindControls(IDictionary dictionary, string prefix)
- {
- BindControls(dictionary, prefix, ListSuffix);
- }
-
- protected void BindControls(IDictionary dictionary)
- {
- BindControls(dictionary, null, ListSuffix);
- }
-
- protected IViewHelper ExecuteBind(string command)
- {
- IViewHelper helper = GetHelperFor(command);
- helper.Execute();
- BindControls(helper.Criteria);
- return helper;
- }
-
- protected void ExecuteBind(IViewHelper helper)
+ /// <summary>
+ /// Set Labels and TextBoxes to an empty string
+ /// to ensure inappropriate values are not carried over.
+ /// </summary>
+ ///
+ protected void ResetControls()
+ {
+ ControlCollection controls = this.Controls;
+ foreach (Control control in controls)
{
- helper.Execute();
- BindControls(helper.Criteria);
- if (helper.IsNominal) helper.Execute();
+ if (IsLabel(control))
+ {
+ Label x = (Label) control;
+ x.Text = String.Empty;
+ }
+ if (IsTextBox(control))
+ {
+ TextBox x = (TextBox) control;
+ x.Text = String.Empty;
+ }
+ if (IsListControl(control))
+ {
+ ListControl x = (ListControl) control;
+ x.SelectedIndex = -1;
+ }
}
+ }
- /// <summary>
- /// Render a control id as a column name
- /// by trimming a prefix from the id, if any.
- /// </summary>
- /// <param name="id">String to process.</param>
- /// <param name="prefix">Prefix to remove.</param>
- /// <returns>id without prefix.</returns>
- ///
- private string ToColumn(string id, string prefix)
- {
- string trimmed;
- if (null == prefix) trimmed = id;
- else trimmed = id.Substring(prefix.Length);
- return trimmed;
- }
+ protected IViewHelper GetHelperFor(string command)
+ {
+ IViewHelper helper = Catalog.GetHelperFor(command);
+ return helper;
+ }
+ protected IViewHelper Execute(string command)
+ {
+ IViewHelper helper = GetHelperFor(command);
+ helper.Execute();
+ return helper;
+ }
- protected void ReadControls(IDictionary dictionary, string[] keys, bool nullIfEmpty)
+ protected void BindControls(IDictionary dictionary, string prefix, string list_suffix)
+ {
+ ControlCollection controls = this.Controls;
+ foreach (Control t in controls)
{
- ControlCollection controls = this.Controls;
- int i = 0;
- foreach (Control t in controls)
- {
- string key = keys[i];
- if (IsTextBox(t))
- {
- TextBox x = (TextBox) t;
- string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
- dictionary.Add(key, value);
- }
- if (IsLabel(t))
- {
- Label x = (Label) t;
- string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
- dictionary.Add(key, value);
- }
- if (IsListControl(t))
- {
- ListControl x = (ListControl) t;
- string value = (nullIfEmpty) ? NullIfEmpty(x.SelectedValue) : x.SelectedValue;
- dictionary.Add(key, value);
- }
- if (IsCheckBox(t))
- {
- CheckBox x = (CheckBox) t;
- string value = (x.Checked) ? key : null;
- dictionary.Add(key, value);
- }
- if (IsRadioButton(t))
- {
- RadioButton x = (RadioButton) t;
- string value = (x.Checked) ? key : null;
- dictionary.Add(key, value);
- }
- i++;
+ if (IsTextBox(t))
+ {
+ TextBox x = (TextBox) t;
+ object v = dictionary[ToColumn(x.ID, prefix)];
+ if (v != null) x.Text = v.ToString();
}
- }
-
- protected void ReadControls(IDictionary dictionary, string prefix, string list_suffix, bool nullIfEmpty)
- {
- ControlCollection controls = this.Controls;
- foreach (Control t in controls)
+ if (IsLabel(t))
+ {
+ Label x = (Label) t;
+ object v = dictionary[ToColumn(x.ID, prefix)];
+ if (v != null) x.Text = v.ToString();
+ }
+ if (IsListControl(t))
{
- if (IsTextBox(t))
- {
- TextBox x = (TextBox) t;
- string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
- dictionary.Add(ToColumn(x.ID, prefix), value);
- }
- if (IsLabel(t))
- {
- Label x = (Label) t;
- string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
- dictionary.Add(ToColumn(x.ID, prefix), value);
- }
- if (IsListControl(t))
- {
- ListControl x = (ListControl) t;
- string root = RootId(x.ID, prefix, list_suffix);
- string value = (nullIfEmpty) ? NullIfEmpty(x.SelectedValue) : x.SelectedValue;
- dictionary.Add(root, value);
- }
- if (IsCheckBox(t))
- {
- CheckBox x = (CheckBox) t;
- string key = ToColumn(x.ID, prefix);
- string value = (x.Checked) ? key : null;
- dictionary.Add(key, value);
- }
- if (IsRadioButton(t))
- {
- RadioButton x = (RadioButton) t;
- string key = ToColumn(x.ID, prefix);
- string value = (x.Checked) ? key : null;
- dictionary.Add(key, value);
- }
+ ListControl x = (ListControl) t;
+ string root = RootId(x.ID, prefix, list_suffix);
+ IList s = dictionary[root + list_suffix] as IList; // this_key_list
+ string r = dictionary[root] as string; // this_key
+ if ((null == r) || (0 == r.Length))
+ BindListControl(x, s);
+ else
+ BindListControl(x, s, r);
}
}
+ }
- protected void ReadControls(IDictionary dictionary, bool nullIfEmpty)
- {
- ReadControls(dictionary,null,ListSuffix,nullIfEmpty);
- }
+ protected void BindControls(IDictionary dictionary, string prefix)
+ {
+ BindControls(dictionary, prefix, ListSuffix);
+ }
- protected IViewHelper Read(string command, bool nullIfEmpty)
- {
- IViewHelper helper = GetHelperFor(command);
- ReadControls(helper.Criteria,nullIfEmpty);
- return helper;
- }
+ protected void BindControls(IDictionary dictionary)
+ {
+ BindControls(dictionary, null, ListSuffix);
+ }
- protected IViewHelper Read(string command)
- {
- return Read(command,true);
- }
+ protected IViewHelper ExecuteBind(string command)
+ {
+ IViewHelper helper = GetHelperFor(command);
+ helper.Execute();
+ BindControls(helper.Criteria);
+ return helper;
+ }
- protected IViewHelper ReadExecute(string command, bool nullIfEmpty)
- {
- IViewHelper helper = Read(command,nullIfEmpty);
- helper.Execute();
- return helper;
- }
+ protected void ExecuteBind(IViewHelper helper)
+ {
+ helper.Execute();
+ BindControls(helper.Criteria);
+ if (helper.IsNominal) helper.Execute();
+ }
- protected IViewHelper ReadExecute(string command)
- {
- return ReadExecute(command,true);
- }
+ /// <summary>
+ /// Render a control id as a column name
+ /// by trimming a prefix from the id, if any.
+ /// </summary>
+ /// <param name="id">String to process.</param>
+ /// <param name="prefix">Prefix to remove.</param>
+ /// <returns>id without prefix.</returns>
+ ///
+ private string ToColumn(string id, string prefix)
+ {
+ string trimmed;
+ if (null == prefix) trimmed = id;
+ else trimmed = id.Substring(prefix.Length);
+ return trimmed;
+ }
- protected IViewHelper Read(string command, IDictionary criteria, bool nullIfEmpty)
- {
- IViewHelper helper = GetHelperFor(command);
- helper.Read(criteria,nullIfEmpty);
- return helper;
- }
-
- protected IViewHelper ReadExecute(string command, IDictionary criteria, bool nullIfEmpty)
- {
- IViewHelper helper = Read(command, criteria, nullIfEmpty);
- helper.Execute();
- return helper;
- }
-
- protected IViewHelper ReadExecute(string command, IDictionary criteria)
- {
- return ReadExecute(command,criteria,true);
- }
-
-
- #region ListControl methods
-
- /// <summary>
- /// Select only those items in control
- /// whose Value property matches the given value.
- /// If the value is null, no action is taken.
- /// </summary>
- /// <param name="control"></param>
- /// <param name="value"></param>
- ///
- protected void SelectItem(ListControl control, string value)
+
+ protected void ReadControls(IDictionary dictionary, string[] keys, bool nullIfEmpty)
+ {
+ ControlCollection controls = this.Controls;
+ int i = 0;
+ foreach (Control t in controls)
{
- if (value != null)
+ string key = keys[i];
+ if (IsTextBox(t))
{
- foreach (ListItem i in control.Items)
- i.Selected = false;
-
- foreach (ListItem i in control.Items)
- {
- if (value.Equals(i.Value))
- i.Selected = true;
- }
+ TextBox x = (TextBox) t;
+ string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
+ dictionary.Add(key, value);
+ }
+ if (IsLabel(t))
+ {
+ Label x = (Label) t;
+ string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
+ dictionary.Add(key, value);
+ }
+ if (IsListControl(t))
+ {
+ ListControl x = (ListControl) t;
+ string value = (nullIfEmpty) ? NullIfEmpty(x.SelectedValue) : x.SelectedValue;
+ dictionary.Add(key, value);
}
+ if (IsCheckBox(t))
+ {
+ CheckBox x = (CheckBox) t;
+ string value = (x.Checked) ? key : null;
+ dictionary.Add(key, value);
+ }
+ if (IsRadioButton(t))
+ {
+ RadioButton x = (RadioButton) t;
+ string value = (x.Checked) ? key : null;
+ dictionary.Add(key, value);
+ }
+ i++;
}
+ }
- /// <summary>
- /// Deactivate the selected item, and select any item matching value.
- /// </summary>
- /// <param name="control"></param>
- /// <param name="value"></param>
- ///
- protected void SelectListItem(ListControl control, string value)
+ protected void ReadControls(IDictionary dictionary, string prefix, string list_suffix, bool nullIfEmpty)
+ {
+ ControlCollection controls = this.Controls;
+ foreach (Control t in controls)
{
- try
+ if (IsTextBox(t))
+ {
+ TextBox x = (TextBox) t;
+ string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
+ dictionary.Add(ToColumn(x.ID, prefix), value);
+ }
+ if (IsLabel(t))
+ {
+ Label x = (Label) t;
+ string value = (nullIfEmpty) ? NullIfEmpty(x.Text) : x.Text;
+ dictionary.Add(ToColumn(x.ID, prefix), value);
+ }
+ if (IsListControl(t))
{
- control.SelectedIndex = -1;
- SelectItem(control, value);
+ ListControl x = (ListControl) t;
+ string root = RootId(x.ID, prefix, list_suffix);
+ string value = (nullIfEmpty) ? NullIfEmpty(x.SelectedValue) : x.SelectedValue;
+ dictionary.Add(root, value);
}
- catch (NullReferenceException e1)
+ if (IsCheckBox(t))
{
- if (e1 == null) value = string.Empty; // placate the IDE
+ CheckBox x = (CheckBox) t;
+ string key = ToColumn(x.ID, prefix);
+ string value = (x.Checked) ? key : null;
+ dictionary.Add(key, value);
+ }
+ if (IsRadioButton(t))
+ {
+ RadioButton x = (RadioButton) t;
+ string key = ToColumn(x.ID, prefix);
+ string value = (x.Checked) ? key : null;
+ dictionary.Add(key, value);
}
}
+ }
- /// <summary>
- /// Bind a list of KeyValue objects to a ListControl,
- /// select any item matching value.
- /// </summary>
- /// <param name="control">ListControl to process</param>
- /// <param name="list">List of TextKey objects.</param>
- /// <param name="value">Value to select, or null if nothing is selected.</param>
- ///
- private void BindListControl(ListControl control, IList list, string value)
- {
- control.DataTextField = "Value";
- control.DataValueField = "Key";
- control.DataSource = list;
- control.DataBind();
- SelectListItem(control, value);
- }
+ protected void ReadControls(IDictionary dictionary, bool nullIfEmpty)
+ {
+ ReadControls(dictionary, null, ListSuffix, nullIfEmpty);
+ }
- protected void BindListControl(ListControl control, IList list)
- {
- bool insertKey = ((list != null) && (!list.Contains(NullKey)));
- if (insertKey) list.Insert(0, NullKey);
- BindListControl(control, list, null);
- }
+ protected IViewHelper Read(string command, bool nullIfEmpty)
+ {
+ IViewHelper helper = GetHelperFor(command);
+ ReadControls(helper.Criteria, nullIfEmpty);
+ return helper;
+ }
+
+ protected IViewHelper Read(string command)
+ {
+ return Read(command, true);
+ }
+
+ protected IViewHelper ReadExecute(string command, bool nullIfEmpty)
+ {
+ IViewHelper helper = Read(command, nullIfEmpty);
+ helper.Execute();
+ return helper;
+ }
+
+ protected IViewHelper ReadExecute(string command)
+ {
+ return ReadExecute(command, true);
+ }
- #endregion
+ protected IViewHelper Read(string command, IDictionary criteria, bool nullIfEmpty)
+ {
+ IViewHelper helper = GetHelperFor(command);
+ helper.Read(criteria, nullIfEmpty);
+ return helper;
+ }
+
+ protected IViewHelper ReadExecute(string command, IDictionary criteria, bool nullIfEmpty)
+ {
+ IViewHelper helper = Read(command, criteria, nullIfEmpty);
+ helper.Execute();
+ return helper;
+ }
+
+ protected IViewHelper ReadExecute(string command, IDictionary criteria)
+ {
+ return ReadExecute(command, criteria, true);
+ }
- #endregion
+ #region ListControl methods
- /// <summary>
- /// Signal when an error is exposed.
- /// </summary>
- public event EventHandler View_Error;
-
- /// <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_Send(object sender, ViewArgs e)
+ /// <summary>
+ /// Select only those items in control
+ /// whose Value property matches the given value.
+ /// If the value is null, no action is taken.
+ /// </summary>
+ /// <param name="control"></param>
+ /// <param name="value"></param>
+ ///
+ protected void SelectItem(ListControl control, string value)
+ {
+ if (value != null)
{
- if (View_Error != null)
+ foreach (ListItem i in control.Items)
+ i.Selected = false;
+
+ foreach (ListItem i in control.Items)
{
- View_Error(sender, e);
+ if (value.Equals(i.Value))
+ i.Selected = true;
}
}
+ }
- /// <summary>
- /// Reset controls to default state, usually after a Quit or Save event.
- /// </summary>
- public virtual void Page_Reset()
+ /// <summary>
+ /// Deactivate the selected item, and select any item matching value.
+ /// </summary>
+ /// <param name="control"></param>
+ /// <param name="value"></param>
+ ///
+ protected void SelectListItem(ListControl control, string value)
+ {
+ try
{
- ResetControls();
+ control.SelectedIndex = -1;
+ SelectItem(control, value);
}
-
- private void Page_Load(object sender, EventArgs e)
+ catch (NullReferenceException e1)
{
- // Put user code to initialize the page here
+ if (e1 == null) value = string.Empty; // placate the IDE
}
+ }
+
+ /// <summary>
+ /// Bind a list of KeyValue objects to a ListControl,
+ /// select any item matching value.
+ /// </summary>
+ /// <param name="control">ListControl to process</param>
+ /// <param name="list">List of TextKey objects.</param>
+ /// <param name="value">Value to select, or null if nothing is selected.</param>
+ ///
+ private void BindListControl(ListControl control, IList list, string value)
+ {
+ control.DataTextField = "Value";
+ control.DataValueField = "Key";
+ control.DataSource = list;
+ control.DataBind();
+ SelectListItem(control, value);
+ }
- #region Web Form Designer generated code
+ protected void BindListControl(ListControl control, IList list)
+ {
+ bool insertKey = ((list != null) && (!list.Contains(NullKey)));
+ if (insertKey) list.Insert(0, NullKey);
+ BindListControl(control, list, null);
+ }
- protected override void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
+ #endregion
+
+ #endregion
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
+ /// <summary>
+ /// Signal when an error is exposed.
+ /// </summary>
+ public event EventHandler View_Error;
+
+ /// <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_Send(object sender, ViewArgs e)
+ {
+ if (View_Error != null)
{
- this.Load += new EventHandler(this.Page_Load);
+ View_Error(sender, e);
}
+ }
+
+ /// <summary>
+ /// Reset controls to default state, usually after a Quit or Save event.
+ /// </summary>
+ public virtual void Page_Reset()
+ {
+ ResetControls();
+ }
- #endregion
+ private void Page_Load(object sender, EventArgs e)
+ {
+ // Put user code to initialize the page here
}
- }
\ No newline at end of file
+
+ #region Web Form Designer generated code
+
+ protected override void OnInit(EventArgs e)
+ {
+ //
+ // CODEGEN: This call is required by the ASP.NET Web Form Designer.
+ //
+ InitializeComponent();
+ base.OnInit(e);
+ }
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.Load += new EventHandler(this.Page_Load);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs?rev=280027&r1=280026&r2=280027&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs Sat Sep 10 12:12:59 2005
@@ -93,4 +93,4 @@
#endregion
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org