Print Page | Close Window

Property interceptor does not update the UI

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4024
Printed Date: 04-May-2025 at 7:28pm


Topic: Property interceptor does not update the UI
Posted By: ichill
Subject: Property interceptor does not update the UI
Date Posted: 09-Mar-2013 at 9:58pm
I'm looking at temphire property interceptor

        [BeforeSet]
        internal void RemoveWhiteSpace(IEntityPropertySetInterceptorArgs args)
        {
            if (args.EntityProperty.DataType != typeof(string) || args.Value ==  null)
                return;

            args.Value = ((string) args.Value).Trim();
        }


When I try to set the firstname to "    Steeve" (double quote not included), the textbox still displays Steeve with the leading spaces.
How come it doesn't display the trimmed value?



Replies:
Posted By: sbelini
Date Posted: 11-Mar-2013 at 11:02am
ichill,

I was not able to see the behavior you described.
I've tried the property interceptor above in the WPF_TourOfDevForce sample and it works as expected.

Please provide a small solution reproducing the issue. (against NorthwindIB)


Posted By: ichill
Date Posted: 11-Mar-2013 at 6:58pm
Hi sbelini,

I tried it on  http://drc.ideablade.com/elqNow/elqRedir.htm?ref=http://apps.ideablade.com/TempHire/ - apps.ideablade.com/TempHire  . I change First name Steven to     Steeve (with leading spaces), tabbed to the next field. I was expecting that the First name will show Steeve without the leading spaces, but it did not. It still shows the First name with leading spaces.


Posted By: mgood
Date Posted: 12-Mar-2013 at 6:42am
ichill, 
If you look at the implementation of StaffingResourceNameEditorViewModel, which is the ViewModel that lets you edit the name, you'll notice that it doesn't set the properties on the entity directly and that the corresponding view is not bound to the entity's properties. 

The entity's properties are set once you Ok out of the popup in StaffingResourceSummaryViewModel (see below). At that point the property interceptor is invoked and the strings are trimmed. If StaffingResourceNameEditorViewModel would set the properties directly, we would have to roll back the entity if the user clicks Cancel and risk losing other pending changes or we would have to reset just the properties with the original values. By not changing the actual properties until the user hits Ok, we don't have to do anything if they click Cancel and the entity remains untouched.

[Export, PartCreationPolicy(CreationPolicy.NonShared)]
    public class StaffingResourceSummaryViewModel : StaffingResourceScreenBase
    {
        private readonly ExportFactory<StaffingResourceNameEditorViewModel> _nameEditorFactory;

[ImportingConstructor]
        public StaffingResourceSummaryViewModel(IUnitOfWorkManager<IResourceMgtUnitOfWork> unitOfWorkManager,
                                                ExportFactory<StaffingResourceNameEditorViewModel> nameEditorFactory)
            : base(unitOfWorkManager)
        {
            _nameEditorFactory = nameEditorFactory;
        }

        public async void EditName()
        {
            var nameEditor = _nameEditorFactory.CreateExport().Value;
            await nameEditor.Start(StaffingResource.Id).ShowDialogAsync();

            StaffingResource.FirstName = nameEditor.FirstName;
            StaffingResource.MiddleName = nameEditor.MiddleName;
            StaffingResource.LastName = nameEditor.LastName;
        }
    }



Print Page | Close Window