LLGBLGenDataSource2 and null values

Posts   
 
    
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 13-Aug-2012 12:07:29   

I am using an LLGBLGenDataSource2 with a FormView. I would like to set one of the field values to 0 whenever the form field value is blank. The datasource control has AllFieldsKeepEmptyStringAsValue="True"

The form has a PeterBlum IntegerTextBox for the UI control. The control behavior is that it returns an integer when the textbox is valid or null when the textbox is blank or has an illegal value.

I put a PreProcessValueToSet in a partial class for that entity. When I enter a valid value and step through the fields in the debugger, I see that it hits that field in the switch statement and evaluates it correctly.



 protected override void PreProcessValueToSet(IEntityField2 fieldToSet, ref object valueToSet)
        {

switch(enumValue)
{
case: ProductFieldIndex.ProductId
break;

case: ProductFieldIndex.UnitsOnOrder
if(valueToSet == null)
{
valueToSet = 0;
}
break;

}

}

However, when I leave the field blank, the field index is never hit. I assume that the DataSourceControl is skipping over the field because it sees the null value. Is there anyway I can get that null value to evalaute it?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Aug-2012 21:21:21   

This can be handled using a Validator. Specificaly through the usage of ValidateEntityBeforeSaving, method.

jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 14-Aug-2012 13:59:17   

This is not working for me, perhaps because the field is defined as not null. Let's say the current value is 2. If I enter a 1, that is the value that I see in the debugger during OnValidateFieldValue or ValidateEntityBeforeSave.

If I enter a blank (value from the form control will be null), then the value reverts back to 2 sometime prior to OnValidateFieldValue or ValidateEntityBeforeSave. I need to find an earlier point in the process.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Aug-2012 20:15:58   

I'm not sure why you want this behavior.

First you could have he field as nullable, and set the default value to 0 in the database. Or you can have the field as non-nullable, and then the user won't e able to set it to blank. People might get around this by some UI tweaks.

i.e. you can handle the TextBox TextCHanges event, and in case of an empty string, you can insert "0" instead, or you can use a "reset" button next to the TextBox, which sets the TextBox to 0, if pressed by user.

jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 15-Aug-2012 12:32:32   

I don't have the ability to change the field. Yes, I can handle it in the form UI but it seems like I ought to be able to handle it via LLBLGen as well.

Right now, I'd just like to know if there is anywhere I can hook into this earlier in the LLBLGen entity lifecycyle.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Aug-2012 22:20:37   

Then the only think I can think of, is to add a custom property that wraps the Original property, but it sets the Original one to 0 if it was set to null or an empty string.

And of course you should bind to the new property.