Print Page | Close Window

validation on xxx.create method

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=709
Printed Date: 03-Feb-2026 at 8:09pm


Topic: validation on xxx.create method
Posted By: DataMan
Subject: validation on xxx.create method
Date Posted: 29-Feb-2008 at 4:09pm
What's the best practice for handling required fields when doing a Create on an object.
When I try entering in a new line it automatically shows the errorprovider saying that the value is invalid.

The example that you have in the tutorial makes it easy because the two required fields in the order summary table CustomerID and EmployeeID are not required fields in the table.  My SQL table has 2 key fields that are required.
 
Thanks
 
 
 




Replies:
Posted By: eileenv
Date Posted: 05-Mar-2008 at 10:37am

How to handle required fields when doing a Create on an object depends on what you want your users to experience. I'm assuming you generated your business objects with Verification turned "on" and its sub-option to generate verifiers. The "Generate predefined verifiers" options means (in effect) that you want DevForce to inscribe "Required" verifiers for every non-null property it generates.

The verifiers are generated with Preset triggers, which means they lock up the UI when the user sets the value to null (more precisely, they throw an exception which causes Data Binding to lock up the UI).
 
This is appropriate most of the time and is the safest thing to do. That is, it is safest to assume that the user should not be able to leave a required field blank once she has started entering data into it.
 
However if you decide that it is OK to allow blank strings temporarily (you should run Verification before the save to catch errors), there are a couple options you can do:
 
  1. You could turn off auto-generation of verifiers (but leave generation of BeforeSetValue and AfterSetValue) and add the verifiers you want in the business logic of the entity.
 
  2. Alternatively, you can programmatically discover the generated required verifiers and change the triggering from Preset to Postset. Postset means the verifier is evaluated after the property is set (no exception is thrown and the user can move out of the control).
 
Hope this helps.



Print Page | Close Window