Validation when databinding

Posts   
 
    
Posts: 11
Joined: 29-Apr-2005
# Posted on: 04-May-2005 20:54:03   

I'm testing out how I will handle validation in the UI. I've been reading previous posts about using the validator classes, but I'm still at a loss with this situation.

I've created a simple winforms user control to test validating entities. In the user control, I simply bind a few textboxes to a few properties on my entity.

    // populate with a participant by pkid
            ProductionParticipantsEntity participant = new ProductionParticipantsEntity(pkid);
            tbFirstName.DataBindings.Add("Text", participant, "FirstName");
            tbLastName.DataBindings.Add("Text", participant, "LastName");
            tbEmail.DataBindings.Add("Text", participant , "Email");

Now, I somewhat understand how to use the validator classes to apply business logic to the validation routine, but what I cant find is how to intercept the very first level of validation which is checking if the changed value will fit in the database field. An example is if I try to put too many characters into the tbFirstName textbox. What happens when I try to tab or click out of the textbox that now contains too many characters for its underlying database field, focus will not leave the textbox because the value is too large for the field. This wont be very intuitive to my users.

When I stepped through the code, it seems like an excpetion is thrown from the support classes object EntityBase. So naturally one approach could be to ovverride the setNewValue method in the ProductionParticipantEntity class and do something there with it. Problem with that approach is..

  • I would like to keep that logic that tells the user about the problem out of the Entity classes as I consider this a UI function.
  • I dont want to have to add that code to every single entity object I have. I realize generating this ovverride might work, but then I would have to know how to handle this situation with the user.
  • I dont know how to know in the user control that this part of validation has failed.

Ulitmately what I am trying to do is create a generic form or usercontrol that when hooked up to an entity object, provides all the fields for edit/add as well as provides the ui logic to tell the user when they've entered invalid data.

Anyone trying to do something similar that might want to collaborate on this effort, or at least offer some ideas on how to solve this problem?

Thanks, Jim

Posts: 11
Joined: 29-Apr-2005
# Posted on: 24-May-2005 19:05:38   

Ding dong... Anyone, anyone?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-May-2005 20:14:59   

I missed this one completely, sorry Jim. I'll get back to you a.s.a.p.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-May-2005 21:30:54   

Jim wrote:

I'm testing out how I will handle validation in the UI. I've been reading previous posts about using the validator classes, but I'm still at a loss with this situation.

I've created a simple winforms user control to test validating entities. In the user control, I simply bind a few textboxes to a few properties on my entity.

    // populate with a participant by pkid
            ProductionParticipantsEntity participant = new ProductionParticipantsEntity(pkid);
            tbFirstName.DataBindings.Add("Text", participant, "FirstName");
            tbLastName.DataBindings.Add("Text", participant, "LastName");
            tbEmail.DataBindings.Add("Text", participant , "Email");

Now, I somewhat understand how to use the validator classes to apply business logic to the validation routine, but what I cant find is how to intercept the very first level of validation which is checking if the changed value will fit in the database field. An example is if I try to put too many characters into the tbFirstName textbox. What happens when I try to tab or click out of the textbox that now contains too many characters for its underlying database field, focus will not leave the textbox because the value is too large for the field. This wont be very intuitive to my users.

When I stepped through the code, it seems like an excpetion is thrown from the support classes object EntityBase. So naturally one approach could be to ovverride the setNewValue method in the ProductionParticipantEntity class and do something there with it.

The action is indeed done there, because the value will cause an exception when the entity is saved. So that's why the value is denied. You can set the maxlength of the textbox to entity.Field[index].MaxLength (adapter) or entity.Field[index].SourceColumnMaxLength (selfservicing). That way the user can't add more characters than the length which will work.

Frans Bouma | Lead developer LLBLGen Pro