I just committed hopefully complete data binding implementation, as well as many other things. I will work on documentation for everything this week, but here is a quick guide.
Basically, there are two new features in the data binding framework. First one is the ability to specify formatter to use (which actually does both formatting and parsing). There are several useful formatters in Spring.Globalization.Formatters namespace, such as CurrencyFormatter, NumberFormatter, DateTimeFormatter, etc. You can also implement your own formatters if you need to, it's fairly simple.
Formatters are used both during data binding and unbinding. When you bind controls to the data model, Parse method is called with the bound control value as an argument, and its result is then passed to the expression evaluation engine instead of raw value when setting property in the model. The opposite happens when you bind model to the controls -- model value is passed to the formatter's Format method, and its result is then used to set the value of the control property.
All out-of-the box formatters use either default or specified culture settings during formatting and parsing, but you can also override different properties for each formatter. Probably the best documentation at this point are formatters' unit tests and the source code. It's fairly simple, actually.
Second major feature is the ability to specify an error message that should be displayed in the case of data binding error (data type mismatch, formatting or parsing exception, etc.). All you need to do is call SetErrorMessage method on the Binding instance, passing message/resource id and an array of error provider ids as parameters:
AddBinding method is heavily overloaded to make everything as simple and concise as possible, and it returns the added instance of the Binding class, which allows you to simply call SetErrorMessage on it as in the example above.Code:BindingManager.AddBinding("myControl.Text", "myModel.SomeValue") .SetErrorMessage("error.myControl.invalidType", "summary", "myControlErrors");
When you configure error message for the binding, binding exception will be swallowed and specified validation error will be displayed instead. Also, if data binding error occurs when binding control values to the model we will remember it and will not overwrite invalid control value with the last valid model value. This is important because it preserves invalid, but updated value in the control and allows user to fix it instead of having to reenter it.
Well, I guess that's it for now. There are several other features in preview state, such as process flow and state management framework, as well as Anthem.NET integration, but I'll leave that for another post. If you would like to play with it take a look at SpringAir2 BookTrip component, which uses all of these new features.
As usual, feedback is very much appreciated.
Regards,
Aleks


Reply With Quote
Thanks!
