Build-in field level validation

Posts   
 
    
Prafull
User
Posts: 24
Joined: 17-Jun-2008
# Posted on: 26-Jun-2008 16:22:30   

Hi,

I am using LLBLGenPro -- 2.6 final Demo version Visual Studio -- 2005 SqlServer -- 2005

I have a datagridview and binding EntityCollection to this grid using Datasource property of the grid.

Where i am trying to enter the value in a cell, field level validation is getting triggered. And if the entered data is not range or in not proper format, an execption of dataerror is being thrown and setting the error text (IDataErrorInfo implementation).

Now here are my concerns: 1. Exception thrown is from datagrid asking to handle DataError event. --- I do not want to handle this exception in the grid and even do not want to show the exception box to user.

I want to keep the value which user has entered and show him the error icon. So that he can correct the value. a. Has LLBLGen already handled this? If yes then how do I make it work?

  1. Error icon (IDataErrorInfo implemetation) is only shown for string fields. For datetime, integer and long fields, exception is thrown by the datagrid and i am not able to move out of the field until the value is corrected. -- Is it possible not to show the exception box? Just show the icon. Once this happens then i am ok if user is not allowed to move out of this cell until he has corrected the data.

Please take a note that I have not made any change in the config file and also did not enable "SD.Tasks.Generic.ValidatorClassesGenerator" task while generating the code.

Thanks and Regards, Prafull

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Jun-2008 12:13:39   

First, I think you should check the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=12938

Prafull
User
Posts: 24
Joined: 17-Jun-2008
# Posted on: 27-Jun-2008 16:45:29   

Walaa wrote:

First, I think you should check the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=12938

I went through these posts. But i guess that does not solve my issue. Let me repharse my issue.

I am using following : 1. DataGridView. 2. LLBLGen Adapter pattern. 3. Using DataAccessAdapter fetching the entity in EntityCollection (non generic version). 4. Binding this EntityCollection to DataGridView datasource. 5. I have not overridden ValidateField or ValidateEntity method.

What i am getting when i am entering more than 200 chars in Name field (Database level there is constraint that length of Name can not be more than 200 chars) 1. Exception raised by the Datagridview 2. red icon indicating error in input 3. Old value of the cell Please attached document for clarification.

What i am expecting is: 1. Red icon indicating error in input 2. New value of the cell so that user can correct it. 3. I do not need to write validate methods for checking database constraints.

In the post you mentioned, he has implemented(overriden) the Validate methods.

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 27-Jun-2008 23:14:49   

I think you'll have to handle the dataError event...

A DataGridView column displays what it gets from its bound property. In case the entered value is rejected, the corresponding property isn't updated so it keeps returning the old value. When this happens, it seems like the grid is restoring the old value but in fact, it is just displaying what it gets from the property (which is the old value).

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Jun-2008 08:01:21   

Suggested in the previously mentioned thread, have you set formattingEnabled to true?

Prafull
User
Posts: 24
Joined: 17-Jun-2008
# Posted on: 30-Jun-2008 19:35:15   

Walaa wrote:

Suggested in the previously mentioned thread, have you set formattingEnabled to true?

There is no such property in datagridview.


this.dgvLLBLGenData.DataSource = this.testNet.GetEntityCollection();

Signature of the function:


public EntityCollection GetEntityCollection()

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Jul-2008 12:44:09   

What i am getting when i am entering more than 200 chars in Name field

LLBLGen Pro has a built-in validation for field's length, which you can disable by the way.

Anyway this field validation is called when there is an attempt to set a field value, in your case the validation returns false, and the field is not set to the new faulty value, that's why the datagridView reverts back to the original value (2-way databinding).

FieldValidation is a LowLevel validation, as I tried to explain in this post: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=12938&StartAtMessage=0&#71876

What you can do for UI validation is to set the the dataGridView's Column MaxInputLength to the required value.

Prafull
User
Posts: 24
Joined: 17-Jun-2008
# Posted on: 01-Jul-2008 15:20:17   

LLBLGen Pro has a built-in validation for field's length, which you can disable by the way.

No, i want to use LLBLGen's built-in validation. I want to reuse.

Anyway this field validation is called when there is an attempt to set a field value, in your case the validation returns false, and the field is not set to the new faulty value, that's why the datagridView reverts back to the original value (2-way databinding).

I am looking for a way where new value can be retained without raising an exception. Just show error icon. I will check before saving.

Based on your response and going through other posts it seems that LLBLGen does not have this feature in built, I will do plumbing.

FieldValidation is a LowLevel validation, as I tried to explain in this post: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=12938&StartAtMessage=0&#71876

What you can do for UI validation is to set the the dataGridView's Column MaxInputLength to the required value.

I have seen other ORMapper where i do not need to do this. So was checking if there something similar available in LLBLGen.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Jul-2008 16:16:16   

The error icon isn't shown if there's no exception, that's how databinding works.

Also, the new, wrong value isn't retained inside the entity, as that would be odd: the value is refused/rejected, so the set action doesn't take place.

Your need to delegate this to the framework is understandable, but you should also understand that what you want is actually backwards: the UI should set a value in the entity if the UI has passed validation.

The entity then checks it again and simply refuses it: the entity has no notion of the UI, so can't do things the UI wants, that's the job of the UI.