-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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());
}
@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`
}
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;
}
}
}
);
Asked: 2013-07-09 17:35:47 +0800
Seen: 31 times
Last updated: Jul 10 '13
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 +0800 )edit