Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Business Objects + Databinding + data validation = my question...

Business Objects + Databinding + data validation = my question...

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpwpfwcfdesign
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris Richner
    wrote on last edited by
    #1

    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

    A 2 Replies Last reply
    0
    • C Chris Richner

      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

      A Offline
      A Offline
      akyriako78
      wrote on last edited by
      #2

      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 set ErrorProvider.Datasource to your object and enjoy the magic.

      C 1 Reply Last reply
      0
      • C Chris Richner

        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

        A Offline
        A Offline
        akyriako78
        wrote on last edited by
        #3

        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[^]

        1 Reply Last reply
        0
        • A akyriako78

          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 set ErrorProvider.Datasource to your object and enjoy the magic.

          C Offline
          C Offline
          Chris Richner
          wrote on last edited by
          #4

          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";

          A 1 Reply Last reply
          0
          • C Chris Richner

            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";

            A Offline
            A Offline
            akyriako78
            wrote on last edited by
            #5

            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); } } }

            C 1 Reply Last reply
            0
            • A akyriako78

              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); } } }

              C Offline
              C Offline
              Chris Richner
              wrote on last edited by
              #6

              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";

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups