Deliverable: Full support
of data binding
All CSLA based BO's fully support data binding both at design time, and at run time, in both Windows and Web form applications. There has been a lot of work put into
the CSLA framework to support all of the interfaces required to make this happen. The result is that we have framework allowing our BO's to work so easily and intuitively,
that it is easy to overlook all the hard work and expertise that we are taking for granted. The book documents the inner workings of CSLA, and reading this makes it clearer the
size of this deliverable. I have the eBook version, and Adobe tells me there is 775 instances of the word "bind" contained within the text.

We get design time data binding. On the left I have a new
blank form, and I am preparing to drag my Customer BO onto it.
Firstly I can specify whether I want VS2005 to create a“detail”
level control for each Customer property, or a single grid containing
a column for each property. I have chosen
detail level controls.
Next, as you can see on the right, I can override which type of
control will be created on a property by property basis. You should
note that the framework has helpfully excluded base class properties
such as IsValid and IsNew from our BO's browse list as we are
unlikely to want to have these showing on our form.
I
then drag and drop my Customer BO onto the blank form, and VS2005
automatically creates and connects all of the controls now shown.
I am using a Windows forms project for my demonstration, and
pretty much the same facility is available for a Web Form project.
This is a great boost to the productivity of UI programmers.
Now
to runtime data binding support. This has
mostly been set up automatically, so there is not a lot to show you.
We can see from our grid's properties that it's Data Source points to
the BindingSource component that was automatically created by the
design time drag and drop discussed above.
We call also see that the columns are connected to underlying BO's
properties. That is that is all that is needed to use BO data within
our programs. We are getting the same degree of data binding services
that we would receive from a heavyweight object such a DataSet,
however our BO's are more lightweight to transport than a DataSet,
and have enhanced features such as business rules as we shall soon
see.
When the UI creates it's BO instance, it then just needs to
connect the BO into the bindingsource controls. The form controls are automatically populated with data.
customerBindingSource.DataSource = _customer;
customerOrdersBindingSource.DataSource = _customer.Orders;
Another example of data binding can be seen in the Save button,
whose enabled property is bound to the IsValid property of my BO.
SaveButton.Enabled = _customer.IsValid;
A data binding event will toggle the save buttons enabled status as the user
breaks and corrects the BO's underlying business rules.
private void customerBindingSource_CurrentItemChanged(object sender, EventArgs e)
{
SaveButton.Enabled = _customer.IsValid;
}
Data binding is also automatically taking care of toggling on and off the error icons
and tooltips which appear whenever a BO's business rule is broken.
The display on the left shows that there are currently two business
rules which have be violated. The Contact Name field has no value,
and an order line has an invalid freight amount.
|