New Posts New Posts RSS Feed: Property interceptor does not update the UI
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Property interceptor does not update the UI

 Post Reply Post Reply
Author
ichill View Drop Down
Newbie
Newbie


Joined: 17-Jan-2013
Location: Philippines
Posts: 2
Post Options Post Options   Quote ichill Quote  Post ReplyReply Direct Link To This Post Topic: Property interceptor does not update the UI
    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?
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
ichill View Drop Down
Newbie
Newbie


Joined: 17-Jan-2013
Location: Philippines
Posts: 2
Post Options Post Options   Quote ichill Quote  Post ReplyReply Direct Link To This Post Posted: 11-Mar-2013 at 6:58pm
Hi sbelini,

I tried it on 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.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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;
        }
    }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down