Strategies for Validating CSLA Objects and Triggering Save in Blazor #4432
Replies: 2 comments 5 replies
-
By default, rules don't run in the data portal create or createchild operation methods. This is for performance reasons. In your case (and in many cases) it is desirable to run rules in those operations, because otherwise things like Just call |
Beta Was this translation helpful? Give feedback.
-
Hello @ossendorf-at-hoelscher , Thank you for your response regarding validation in CSLA. As I understand it, calling BusinessRules.CheckRules() should validate the object, and the property this.IsValid should accurately reflect the validation state. However, I have a few questions about the implementation: Override of AddBusinessRules: You mentioned that I need to ensure that base.AddBusinessRules() is called in my override of AddBusinessRules. My understanding is that if I do not call this base method, the validation attributes from Data Annotations will not be processed. However, if I'm not overriding the AddBusinessRules method in my class, will it still be called by default, and will the validation rules be evaluated? Use of Data Annotations: I have properties that are decorated with Data Annotations attributes, but when I instantiate my CSLA object using the Create() method, it seems that the validations are still not applied, and this.IsValid remains true. Are there additional configurations I should consider to ensure that both business rules and validations work correctly? [Display(Name = "BIZDEAL_CODE")] Manual Checks: In case the validations do not apply even after ensuring that AddBusinessRules is correctly overridden, should I implement any manual checks or additional validations in my code to enforce these required properties? Here is the code I’m currently working with for creating the object: [Create]
} I would appreciate any further clarification or guidance on this topic, as ensuring that the objects are valid before proceeding is crucial. Thank you in advance for your help! |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a CSLA class called BusinessDeal whose graph is complex because it has many child classes such as BusinessDealAnnex and, in turn, BusinessDealAnnexClient. In a Blazor page, I manage the class, and to manage the list of children (BusinessDealAnnex) and grandchildren (BusinessDealAnnexClient), I use components on the main page. On the main page, I have buttons that allow saving changes made to the BusinessDeal object and its children to the database.
But I want to enable the Save button when at least the required fields for the root object and its children have information. Although the required properties are defined with their attributes indicating that they are required and the minimum lengths for string properties, the class remains valid even when those fields have not been filled.
Here is an example of the definition of some properties:
[Display(Name = "BIZDEAL_ID")]
[Required(ErrorMessage = "The BizdealId field is required")]
public static readonly PropertyInfo BizdealIdProperty = RegisterProperty(nameof(BizdealId));
public Decimal BizdealId
{
get => GetProperty(BizdealIdProperty);
set => SetProperty(BizdealIdProperty, value);
}
[Display(Name = "BIZDEAL_TYPE")]
[Required(ErrorMessage = "The BizdealType field is required")]
public static readonly PropertyInfo BizdealTypeProperty = RegisterProperty(nameof(BizdealType));
public Int16 BizdealType
{
get => GetProperty(BizdealTypeProperty);
set => SetProperty(BizdealTypeProperty, value);
}
[Display(Name = "BIZDEAL_CODE")]
[Required(ErrorMessage = "The BizdealCode field is required")]
[StringLength(30, ErrorMessage = "The BIZDEAL_CODE field cannot exceed 30 characters")]
public static readonly PropertyInfo BizdealCodeProperty = RegisterProperty(nameof(BizdealCode));
public String BizdealCode
{
get => GetProperty(BizdealCodeProperty);
set => SetProperty(BizdealCodeProperty, value);
}
I need to do something additional for CSLA to detect that the conditions of the properties are not met and mark the object as invalid if the attributes are not satisfied.
What is the best way in the graphical interface to validate that the object is complete in order to enable the save button?
Any help will be appreciated.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions