ProjectTracker ProjectEdit empty project saving allowed?!

ProjectTracker ProjectEdit empty project saving allowed?!

Old forum URL: forums.lhotka.net/forums/t/806.aspx


cultofluna posted on Thursday, August 03, 2006

Hello,

I'm truly sorry if my question was already answered many times before, but I could not find the answer yet.
I'm new to the CSLA and after I studied the book I've started testing the ProjectTracker demo. Something strikes me as being kind of strange; When creating a project the Save button is immediately enabled.  I am able to save an empty project (no description, etc.) without the CSLA complaing about any BrokenRules.
Has this got something to do with the use of binding? Is binding slow in any kind of way?

Thanks in advance for any answer.

Best regards,


cultofluna replied on Friday, August 04, 2006

It seems to go wrong with the if(_name != value) check in the set of the Name property. When the _name == "" and value == "" according to the rules of the Name the rules are broken, however the if statement prevents this check when initializing the value.

Cheers

ajj3085 replied on Friday, August 04, 2006

I think that's a bug in the sample code; just before DataPortal_Create exits, it should be calling ValidationRules.CheckRules().   This topic comes up from time to time.. but its fixed in the latest version (2.0.3, in C# at least). 

Try grabbing that version and trying again.

Andy

cultofluna replied on Friday, August 04, 2006

I'm using CSLA 1.0 and I can't seem to find ValidationRules.

I've tried calling BrokenRules.CheckRules(),  however this does not do the trick. Is ValidationRules new in CSLA 2.0?

Brian Criswell replied on Friday, August 04, 2006

ValidationRules is the new form of BrokenRules in CSLA 2.0.

Could you post your DataPortal_Create() method?

cultofluna replied on Friday, August 04, 2006

    // called by DataPortal so we can set defaults as needed
    protected override void DataPortal_Create(object criteria)
    {
      // for this object the criteria can be ignored on creation
      _id = Guid.NewGuid();
      Started = DateTime.Today.ToShortDateString();
      Name = String.Empty;
     
      //***** Added for testing
      BrokenRules.CheckRules();
    }

Brian Criswell replied on Friday, August 04, 2006

Could you post the rule handler methods you are using?

cultofluna replied on Friday, August 04, 2006

I'm sorry I don't quite understand; You mean the following:

          BrokenRules.Assert("NameLen", "Name too long", (value.Length > 50));
          BrokenRules.Assert("NameRequired", "Project name required",

etc.?

Brian Criswell replied on Friday, August 04, 2006

Ah, if you are going to use BrokenRules.CheckRules() you need to set up delegates for your rules instead of using BrokenRules.Assert().  Look for examples of BrokenRules.Add on the forum or on Rocky's website in the errata for version 1.x.

http://www.lhotka.net/Article.aspx?id=12983bcf-4599-4a11-917c-72f3d473883e  You then call BrokenRules.CheckRules("PropertyName") to check all of the rules for a property.

cultofluna replied on Friday, August 04, 2006

Dear Brian,

Thanks alot, this is what I was looking for. I will try using it immediately and post the results...

Best regards,

RockfordLhotka replied on Friday, August 04, 2006

If you are using version 1.0 I recommend at least upgrading to 1.2, as some important bugs were fixed (www.lhotka.net/cslanet/download10.aspx) and you want those fixes.

However, if you upgrade to 1.3 or higher (1.53 is the latest) then you'll get an earlier version of the ValidationRules concept that is in 2.0 and that will make your life easier.

If you want to continue using BrokenRules.Assert(), there are some good threads on the old forum (www.searchcsla.com to search) about ways to consolidate your rules. One common approach is to create a private CheckRules() method that contains all your Assert() calls within a swtich/Select block organized by property. This keeps the rules centralized, and allows you to relatively easily call them from each property set, and other locations in your code (like when you create a new object).

cultofluna replied on Wednesday, August 09, 2006

Thanks for your answer. I'm sorry, I made a mistake, because I am using 1.53. At this moment I can't make the upgrade to 2005 yet, however with your tips and Brian's I think I will be able to handle this problem for now. Hoping to find out about 2.0 soon though!

Best regards

Copyright (c) Marimer LLC