Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: New & Improved

  1. #1
    Join Date
    Sep 2004
    Location
    Belgrade, Serbia
    Posts
    613

    Default New & Improved

    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:

    Code:
    BindingManager.AddBinding("myControl.Text", "myModel.SomeValue")
                           .SetErrorMessage("error.myControl.invalidType", "summary", "myControlErrors");
    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.

    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

  2. #2
    Join Date
    Sep 2005
    Posts
    16

    Default User Controls

    Aleks,

    This new code looks great. But what about for User Controls? I didn't see a User Control in the BookTrip example and there's no InitializeDataBindings to override for a User Control, like there is for a Spring Page.

    Thanks,
    Jamie

  3. #3
    Join Date
    Sep 2004
    Location
    Belgrade, Serbia
    Posts
    613

    Default

    Damn, you are right... I completely forgot about that, which means I'm not finished with data binding

    I will add data binding support for the user controls later today, I hope.

    Thanks,

    Aleks

  4. #4
    Join Date
    Jan 2006
    Location
    Manila, Philippines
    Posts
    27

    Default

    Exactly what I needed Aleks Thanks!

  5. #5
    Join Date
    Jan 2006
    Location
    Manila, Philippines
    Posts
    27

    Default

    Umm, Aleks, I can't seem to find the SetErrorMessage() method you specified above. What I can see is an ErrorMessage property that has an Add() method with several overloads.

    Is it supposed to be like that?

  6. #6
    Join Date
    Sep 2004
    Location
    Belgrade, Serbia
    Posts
    613

    Default

    Nope, that's not how it should be...

    I just checked, and this piece of code works just fine for me:

    Code:
    BindingManager.AddBinding(...).SetErrorMessage(...);
    - Aleks

  7. #7
    Join Date
    Jan 2006
    Location
    Manila, Philippines
    Posts
    27

    Default

    Aleks, the following is the version tag in the DataBindingManager class including the 03/13 nightly snapshot:

    Code:
      /// <version>$Id&#58; DataBindingManager.cs,v 1.1 2006/02/22 11&#58;15&#58;25 aseovic Exp $</version>
    Maybe you haven't uploaded the new file to the CVS?

    -Jon

  8. #8
    Join Date
    Sep 2004
    Location
    Belgrade, Serbia
    Posts
    613

    Default

    Oh, file is in CVS all right, but that's not the right version... Looks like it didn't make it to snapshot on the 13th (it was committed that same night).

    This is what you should have:

    Code:
    /// <version>$Id&#58; DataBindingManager.cs,v 1.2 2006/03/13 11&#58;57&#58;46 aseovic Exp $</version>
    Try one of the later nightly builds.

    Later,

    Aleks

  9. #9
    Join Date
    Jan 2006
    Location
    Manila, Philippines
    Posts
    27

    Default

    Unfortunately it seems that there hasn't been any nightly build after 3/13.

    Anyway, I'll just try getting it directly from the CVS... or if that doesn't work, wait for a new build.

  10. #10
    Join Date
    Mar 2006
    Location
    Ukraine, CR
    Posts
    11

    Default A Problem with latest SpringAir2

    Hi Aleks!

    You are rock! and process implementation is really wanted feature for me. But when I was trying to run SpringAir2 to have a look at it in action I got the following error:

    System.InvalidCastException was unhandled by user code
    Message="Unable to cast object of type 'ASP.web_booktrip_tripform_aspx' to type 'SpringAir.Controllers.BookTripController'."
    Source="App_Web_ov3kqake"
    StackTrace:
    at TripForm.get_Controller() in c:\home\projects\Spring.NET\examples\Spring\Spring Air\src\SpringAir2.Web\Web\BookTrip\TripForm.aspx. cs:line 58
    at TripForm.BindAirportDropdowns() in c:\home\projects\Spring.NET\examples\Spring\Spring Air\src\SpringAir2.Web\Web\BookTrip\TripForm.aspx. cs:line 129
    at TripForm.OnInitializeControls(EventArgs e) in c:\home\projects\Spring.NET\examples\Spring\Spring Air\src\SpringAir2.Web\Web\BookTrip\TripForm.aspx. cs:line 110
    at Spring.Web.UI.Page.OnLoad(EventArgs e) in C:\home\projects\Spring.NET\src\Spring\Spring.Web\ Web\UI\Page.cs:line 253
    at System.Web.UI.Control.LoadRecursive()
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Could you help and give a comment how can I fix it ? I relly want to try this new feature with controllers Thanks in advance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •