0

NotifyChange happening "async" when Messagebox with EventListener?

asked 2013-07-09 17:35:47 +0000

rickcr gravatar image rickcr
704 7

I want to be able to prompt the user when they attempt to delete something and if they click "yes" I want to refresh my list items in the UI after the delete takes place.

At first I thought this would work:

@NotifyChange({"items"})
@Command
public void delete() {
    Messagebox.show("Do you really want to Delete this Item?", "Delete Item", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION,
        new EventListener() {
            public void onEvent(Event evt) {
                switch (((Integer)evt.getData()).intValue()) {
                    case Messagebox.YES:
                        tierService.deleteTierItem(selectedItemCopy.getCode());
                        break;
                    case Messagebox.NO: break;
                }
            }
        }
    ); 
}

The problem with the above is that the notifyChange seems to fire BEFORE the confirmation of the delete.

The way I'm currently handling it seems extremely 'goofy' - I call a GlobalCommand from my Event handler:

@Command
public void delete() {
    Messagebox.show("Do you really want to Delete this Item?", "Delete Item", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION,
        new EventListener() {
            public void onEvent(Event evt) {
                switch (((Integer)evt.getData()).intValue()) {
                    case Messagebox.YES:
                        BindUtils.postGlobalCommand(null, null, GlobalValues.DELETE_TIER_ITEM, null);
                        break;
                    case Messagebox.NO: break;
                }
            }
        }
    );
}

@NotifyChange({"items"})
@GlobalCommand(GlobalValues.DELETE_TIER_ITEM)
public void deleteTierItem(@BindingParam("code") String code) {
    tierService.deleteTierItem(selectedItemCopy.getCode());
}
delete flag offensive retag edit

Comments

You are correct - the modal messagebox interferes with the message queue, and I've had to implement the same postGlobalCommand solution. Else where I've posted a feature request for a new MVVM annotation called '@confirm' that would allow such user prompts to set into a onClick event.

davout ( 2013-07-09 20:08:45 +0000 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-07-10 06:53:45 +0000

nsharma gravatar image nsharma flag of India
917 1 11

updated 2013-07-10 06:55:49 +0000

@notifychange works only with @command annotation:

do the same way as you were doing in your first case ,no need of having @global command annotation.

at the end of your method do like:

 BindUtils.postNotifyChange(null, null, classname.this, "*");

example:

 @Command
    public void delete() {
        Messagebox.show("Do you really want to Delete this Item?", "Delete Item", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION,
            new EventListener() {
                public void onEvent(Event evt) {
                    switch (((Integer)evt.getData()).intValue()) {
                        case Messagebox.YES:
                           deleteTierItem();
                            break;
                        case Messagebox.NO: break;
                    }
                }
            }
        ); 
    }

and

 public void deleteTierItem( ) {
        tierService.deleteTierItem(selectedItemCopy.getCode());
        BindUtils.postNotifyChange(null, null, classname.this, "*");`//code added`
    }
link publish delete flag offensive edit

Comments

Nice. I like that better!

rickcr ( 2013-07-10 14:39:56 +0000 )edit

my pleasure to help you man! good luck

nsharma ( 2013-07-10 14:57:03 +0000 )edit
1

answered 2013-07-10 05:55:45 +0000

hswain gravatar image hswain flag of India
1765 3 10
http://corejavaexample.bl...

don't use BindUtils.postGlobalCommand

Messagebox.show("Do you really want to Delete this Item?", "Delete Item", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION,
        new EventListener() {
            public void onEvent(Event evt) {
                switch (((Integer)evt.getData()).intValue()) {
                    case Messagebox.YES:
                        BindUtils.postNotifyChange(null, null, classname.this, "*");
                        break;
                    case Messagebox.NO: break;
                }
            }
        }
    );
link publish delete flag offensive edit

Comments

Nice this works well. Although I also added the delete call in the YES cas and was specific about what to notify (vs using "*"). Thanks.

rickcr ( 2013-07-10 14:45:24 +0000 )edit

BindUtils.postNotifyChange(null, null, classname.this, "items"); * means all object

hswain ( 2013-07-11 07:04:26 +0000 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-07-09 17:35:47 +0000

Seen: 26 times

Last updated: Jul 10 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More