Business Objects + Databinding + data validation = my question...
-
Hi, Imaginge that one is dealing with business objects which are exposing their attributes through public properties. One is now able to bind these properties to UI Controls with the build-in .net data binding mechanism. So far so good. Data validation should be done inside the business objects in two different modes. Every public property on a business object can have a ValidateXXX method which validate just the given value. The second method validates all given data in a context that is meaningfuel for the whole business object instance. Last but not least all validation messages should be displayed at UI level with an ErrorProvider component. Each control should show the assigned validation error message from the business logic layer. So far we have some business objects, which are bound to UI controls. We have a collection with validation messages provided by the business object instance. How to connect the whole thing togheter? The databinding mechanism is the only part that knows which UI Control is bound to which business object property. I miss the part which takes care of settings the validation messages for each control after validation is done. Shouldn't the databinding mechanism provide a way to transport validation messages and shows them with a ErrorProvider next to the bound control :confused: myMsg.BehindDaKeys = "Jerry Maguire"; -- modified at 11:22 Wednesday 1st March, 2006
-
Hi, Imaginge that one is dealing with business objects which are exposing their attributes through public properties. One is now able to bind these properties to UI Controls with the build-in .net data binding mechanism. So far so good. Data validation should be done inside the business objects in two different modes. Every public property on a business object can have a ValidateXXX method which validate just the given value. The second method validates all given data in a context that is meaningfuel for the whole business object instance. Last but not least all validation messages should be displayed at UI level with an ErrorProvider component. Each control should show the assigned validation error message from the business logic layer. So far we have some business objects, which are bound to UI controls. We have a collection with validation messages provided by the business object instance. How to connect the whole thing togheter? The databinding mechanism is the only part that knows which UI Control is bound to which business object property. I miss the part which takes care of settings the validation messages for each control after validation is done. Shouldn't the databinding mechanism provide a way to transport validation messages and shows them with a ErrorProvider next to the bound control :confused: myMsg.BehindDaKeys = "Jerry Maguire"; -- modified at 11:22 Wednesday 1st March, 2006
Hi, I have faced exactly the same problem and i concluded that my BusinessObject in order to perform proper data-bound functionality has to implement 3 interfaces:
IDataErrorInfo INotifyPropertyChanged IEditableObject
Chris Richner aka Jerry Maguire wrote:
Shouldn't the databinding mechanism provide a way to transport validation messages and shows them with a ErrorProvider next to the bound control
As long as you have implemented
IDataErrorInfo
just setErrorProvider.Datasource
to your object and enjoy the magic. -
Hi, Imaginge that one is dealing with business objects which are exposing their attributes through public properties. One is now able to bind these properties to UI Controls with the build-in .net data binding mechanism. So far so good. Data validation should be done inside the business objects in two different modes. Every public property on a business object can have a ValidateXXX method which validate just the given value. The second method validates all given data in a context that is meaningfuel for the whole business object instance. Last but not least all validation messages should be displayed at UI level with an ErrorProvider component. Each control should show the assigned validation error message from the business logic layer. So far we have some business objects, which are bound to UI controls. We have a collection with validation messages provided by the business object instance. How to connect the whole thing togheter? The databinding mechanism is the only part that knows which UI Control is bound to which business object property. I miss the part which takes care of settings the validation messages for each control after validation is done. Shouldn't the databinding mechanism provide a way to transport validation messages and shows them with a ErrorProvider next to the bound control :confused: myMsg.BehindDaKeys = "Jerry Maguire"; -- modified at 11:22 Wednesday 1st March, 2006
By the way i face a complication so as long as you deal with business objects binding have you solved this ? http://www.codeproject.com/script/comments/forums.asp?msg=1348255&forumid=1649&mode=all&userid=319111#xx1348255xx[^]
-
Hi, I have faced exactly the same problem and i concluded that my BusinessObject in order to perform proper data-bound functionality has to implement 3 interfaces:
IDataErrorInfo INotifyPropertyChanged IEditableObject
Chris Richner aka Jerry Maguire wrote:
Shouldn't the databinding mechanism provide a way to transport validation messages and shows them with a ErrorProvider next to the bound control
As long as you have implemented
IDataErrorInfo
just setErrorProvider.Datasource
to your object and enjoy the magic.Hi predragzakisevic, I'm trying to solve my problem with your solution. I didn't implement IEditableObject, just added IDataErrorInfo. The problem is raised when I try to attach the business object to the error provider as a datasource. It saids that it's invalid because my business object doesn't implement IList. How did you implemented yor business objects? Thanks for you answer btw. myMsg.BehindDaKeys = "Jerry Maguire";
-
Hi predragzakisevic, I'm trying to solve my problem with your solution. I didn't implement IEditableObject, just added IDataErrorInfo. The problem is raised when I try to attach the business object to the error provider as a datasource. It saids that it's invalid because my business object doesn't implement IList. How did you implemented yor business objects? Thanks for you answer btw. myMsg.BehindDaKeys = "Jerry Maguire";
class BusinessObject : IDataErrorInfo,INotifyPropertyChanged,IEditableObject ... { private Dictionary m_Errors = new Dictionary(); string IDataErrorInfo.Error { get { return ((m_Errors.Count > 0) ? "Business object is in an invalid state" : string.Empty); } } string IDataErrorInfo.this[string columnName] { get { ///Fetch from dictionary; return GetErrorDescription(columnName); } } }
-
class BusinessObject : IDataErrorInfo,INotifyPropertyChanged,IEditableObject ... { private Dictionary m_Errors = new Dictionary(); string IDataErrorInfo.Error { get { return ((m_Errors.Count > 0) ? "Business object is in an invalid state" : string.Empty); } } string IDataErrorInfo.this[string columnName] { get { ///Fetch from dictionary; return GetErrorDescription(columnName); } } }
Hi predragzakisevic, Thank you for your code snippet. Maybe it's not working because I'm running against .net 1.1. Maybe they changed the way the errorprovider works in .net 2.0. If I try to set the errorprovider.datasource which an object that not implement IList I get an exception. As far as I can see your code doesn't implement IList. I wrote my own DataProvider implementation under .net 1.1 that does the job as well. Great to have your feedback about this topic. Have a nice day myMsg.BehindDaKeys = "Jerry Maguire";