Blazor CslaValidationMessages SmartDate #1992
Unanswered
JurjendeGroot
asked this question in
General
Replies: 3 comments 3 replies
-
Can you try binding the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hello Rocky,
Thank you for your response. 😊
I have removed the DevExpress controls and now use the regular input controls.
I have the InputDate control bound to the SmartDate BusinessObject property and it would seem databinding does not supported the ‘Csla.SmartDate’ type as it throws an Exception in the Output-window (see below). (After doing some searching it turns out Blazor databinding supports only some basic types: string, int, DateTime, enum and bool)
<EditForm Model="person" OnSubmit="@formsubmit">
<CslaValidator />
<ValidationSummary />
<label for="FirstName">FirstName* :</label>
<InputText @bind-Value="@person.FirstName" />
<CslaValidationMessages For="() => person.FirstName" />
<label for="LastName">LastName *:</label>
<InputText @bind-Value="@person.LastName" />
<CslaValidationMessages For="() => person.LastName" />
<label for="DateService">Date service (model):</label>
<InputDate id="DateService" @bind-Value="@person.DateService" />
<CslaValidationMessages For="() => person.DateService" />
<input type="submit" value="Save" class="btn btn-primary" disabled="@(!person.IsSavable)" />
</EditForm>
<b><label>BrokenRules:</label></b>
<br />
@foreach (var rule in person.BrokenRulesCollection)
{
<label>@rule.Property - @rule.Description </label>
<br />
}
}
@code {
Person person;
public void FormSubmit(EditContext editContext)
{
Console.WriteLine("");
}
protected override async Task OnParametersSetAsync()
{
person = await vCoreJurModule.BusinessObjects.Person.NewAsync();
}
}
properties in Person:
public static readonly PropertyInfo<SmartDate> DateServiceProperty = RegisterProperty<SmartDate>(c => c.DateService);
public SmartDate DateService
{
get => GetProperty(DateServiceProperty);
set => SetProperty(DateServiceProperty, value);
}
Error in the Output-Window:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The type 'Csla.SmartDate' is not a supported date type.
System.InvalidOperationException: The type 'Csla.SmartDate' is not a supported date type.
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x2b55be0 + 0x000ce> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x38fb5f8 + 0x000da> in <filename unknown>:0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x339b788 + 0x000b6> in <filename unknown>:0
Trying to get things working, I’ve added a string property to the page, ‘DateServiceStr’ wich acts as a go-between between the UI and BusinessObject. This however results in an other error, I guess that since the bound-property is part of the razor-page, the razor-page is now communicated as begin the ‘model’ and the page offcourse does not implement the ICheckRules interface ? (When I have the razor-page implement ICheckRules the error goes away (code not included), but the brokenrule for SmartDate is NOT shown in the CslaValidationMessages control or ValidationSummary)
<EditForm Model="person" OnSubmit="@formsubmit">
<CslaValidator />
<ValidationSummary />
<label for="FirstName">FirstName* :</label>
<InputText @bind-Value="@person.FirstName" />
<CslaValidationMessages For="() => person.FirstName" />
<label for="LastName">LastName *:</label>
<InputText @bind-Value="@person.LastName" />
<CslaValidationMessages For="() => person.LastName" />
<label for="DateServiceText">Date service (tekst):</label>
<InputText Id="DateServiceText" @bind-Value="@DateServiceStr" />
<CslaValidationMessages For="() => person.DateService" />
<input type="submit" value="Save" class="btn btn-primary" disabled="@(!person.IsSavable)" />
</EditForm>
<b><label>BrokenRules:</label></b>
<br />
@foreach (var rule in person.BrokenRulesCollection)
{
<label>@rule.Property - @rule.Description </label>
<br />
}
}
@code {
Person person;
public string DateServiceStr
{
get { return person.DateService.Text; }
set { person.DateService = new SmartDate(value); }
}
public void FormSubmit(EditContext editContext)
{
Console.WriteLine("");
}
protected override async Task OnParametersSetAsync()
{
person = await vCoreJurModule.BusinessObjects.Person.NewAsync();
}
}
Error in the Output-Window:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Model does not implement required interface ICheckRules
System.ArgumentException: Model does not implement required interface ICheckRules
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x2b55138 + 0x000ce> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x3509088 + 0x000da> in <filename unknown>:0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x338e2f0 + 0x000b6> in <filename unknown>:0
The thread 0x0 has exited with code 0 (0x0).
The program 'localhost:44358' has exited with code -1 (0xffffffff).
The program '' has exited with code -1 (0xffffffff).
The program '[34484] iisexpress.exe' has exited with code -1 (0xffffffff).
[cid:image001.png@01D6D6E8.6F5D98D0]
I have looked into the Csla MVVM pattern implementation, I haven’t spent too much time on that, but I couldn’t get the brokenrules to show there either.
I guess for my situation, in wich we make frequent use of DomainObjects like SmartDate, but also our own SmartAmount, Currency, EmailAddress, PhoneNumber, Numberplate, FileSize etc… we might need to create ‘go-between’ properties to solve this .
Just to test this, I have now added the following property to my BusinessObject
public string DateServiceStr
{
get { return DateService.Text; }
set { DateService = new SmartDate(value); }
}
and now the ‘Model does not implement required interface ICheckRules’ Exception does NOT appear in the output-window, however the brokenrule is not shown in ValidationSummary or in the CslaValidationMessages just below the Date-Service input-box
<EditForm Model="person" OnSubmit="@formsubmit">
<CslaValidator />
<ValidationSummary />
<label for="FirstName">FirstName* :</label>
<InputText @bind-Value="@person.FirstName" />
<CslaValidationMessages For="() => person.FirstName" />
<label for="LastName">LastName *:</label>
<InputText @bind-Value="@person.LastName" />
<CslaValidationMessages For="() => person.LastName" />
<label for="DateServiceText">Date service (tekst):</label>
<InputText Id="DateServiceText" @bind-Value="person.DateServiceStr" />
<CslaValidationMessages For="() => person.DateService" />
<input type="submit" value="Save" class="btn btn-primary" disabled="@(!person.IsSavable)" />
</EditForm>
<b><label>BrokenRules:</label></b>
<br />
@foreach (var rule in person.BrokenRulesCollection)
{
<label>@rule.Property - @rule.Description </label>
<br />
}
[cid:image002.png@01D6D6EA.A0FF5E30]
I guess somehow the ‘smart’ DomainObjects will have to ‘fool’ the blazor binding mechanism into thinking that the object is one of the 5 supported data-types for binding. At this time I’m not sure how to achieve that...
Thanks,
Jurjen de Groot
Netherlands
From: Rockford Lhotka <notifications@github.com>
Sent: Friday, 18 December 2020 17:15
To: MarimerLLC/csla <csla@noreply.github.com>
Cc: Jurjen de Groot <jurjen@gits-online.nl>; Author <author@noreply.github.com>
Subject: Re: [MarimerLLC/csla] Blazor CslaValidationMessages SmartDate (#1992)
Can you try binding the SmartDate property to a simple text input control? I'd like to eliminate any possible complexity from the devexpress controls. Basically try to figure out if it is the control, the SmartDate type, or a combination of both.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#1992 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABBSZ5EKODTSPROXJVRLZI3SVN5XPANCNFSM4U77IUCQ>.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
That’s true, so maybe that’s not the best way to go about it. But I would still expect the BrokenRules for a smartdate (or other ‘smart’ object property) to appear in the various controls ValidationSummary and CslaValidationMessages …
From: Rockford Lhotka <notifications@github.com>
Sent: Monday, 21 December 2020 01:31
To: MarimerLLC/csla <csla@noreply.github.com>
Cc: Jurjen de Groot <jurjen@gits-online.nl>; Author <author@noreply.github.com>
Subject: Re: [MarimerLLC/csla] Blazor CslaValidationMessages SmartDate (#1992)
Keep in mind that the primary reason SmartDate exists is to support binding to a text field so the user can enter various date formats or parts of dates without having to be too precise.
I think a lot of the utility of the type is lost if you are binding it to a date-style UI control, where all the nifty text<->date translation features aren't necessary.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#1992 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABBSZ5GIKSKUP2N6YMQXF5TSV2JKTANCNFSM4U77IUCQ>.
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm using Blazor with Csla and am experiencing some problems with CslaValidationMessages when using it with a SmartDate property, when using with a string property like LastName it works just fine.
this problem also seems to occur in the ValidationSummary, just but the brokenRules from string properties are shown, not for domain-object properties like SmartDate properties. I checked and the brokenrules for these SmartDate properties do exist in the BusinessObject.
All brokenrules have severity 'Error'.
As mentioned in the book I'm using in my razor code
....
Has anyone had this same experience ?
Kind regards,
Jurjen de Groot
Beta Was this translation helpful? Give feedback.
All reactions