0

Problem with 'NotifyChange' and 'Messagebox'?

asked 2012-09-11 19:51:13 +0800

davout gravatar image davout
1435 3 18

updated 2012-09-11 19:56:07 +0800

I have a MVVM class method handling a user action to delete an entry. The code inside the MVVM class method displays a messagebox to prompt a confirmation from the user.

The use of this messagebox seems to interfere with the 'NotifyChange' related updates.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Command("deleteSelected")
@NotifyChange({"locationModel","selectedLocation","showEdit"})
public void deleteSelected() {
   if (getSelectedLocation() != null) {
      try {
         if (geoLocationManager.isUsed(getSelectedLocation().getData().getID())) {
            Messagebox.show("This Location cannot be deleted as it is being used by requirements or available resources","Delete", Messagebox.OK, Messagebox.INFORMATION);
         }
         else {
            Messagebox.show("Confirm deletion of ["+getSelectedLocation().getData().getTitle()+"]?", "Confirm Dialog", Messagebox.OK | Messagebox.CANCEL,
						Messagebox.QUESTION, new org.zkoss.zk.ui.event.EventListener() {
               public void onEvent(Event evt) throws InterruptedException {
                  if (evt.getName().equals("onOK")) {
                     try {
                        geoLocationManager.delete(getSelectedLocation().getData().getID());
                        buildModel();
                        setSelectedLocation(null);
                        BindUtils.postNotifyChange(DataAreaIDs.QUEUE_NAME,DataAreaIDs.QUEUE_SCOPE,this,"showEdit"); 
                        BindUtils.postNotifyChange(DataAreaIDs.QUEUE_NAME,DataAreaIDs.QUEUE_SCOPE,this,"locationModel"); 
                     }
                     catch (PersistenceException e) {
                        showErrorView(getCommand(), e);
                     }
                     catch (UnknownGeoLocationException e) {
                     }
                  }
               }
             });
	}
}
catch (PersistenceException e) {
   showErrorView(getCommand(), e);
}
		}
	}




I've even tried forcing the refresh using the 'bindUtils' calls, but the view remains unaffected.

Any ideas?

delete flag offensive retag edit

11 Replies

Sort by ยป oldest newest

answered 2012-09-12 05:58:41 +0800

davout gravatar image davout
1435 3 18

If I take out the 'Messagebox.show' code, like:

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Command("deleteSelected")
	@NotifyChange({"locationModel","selectedLocation","showEdit"})
	public void deleteSelected() {
		try {
			geoLocationManager.delete(getSelectedLocation().getData().getID());
			buildModel();
			setSelectedLocation(null);
		}
		catch (UnknownGeoLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (PersistenceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	


... the @NotifyChange updates refresh the page correctly.

Is this a bug? Should I be building some client side code to handle the user confirmation prompt?

link publish delete flag offensive edit

answered 2012-09-12 07:09:17 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

No Need to put any Client Site Coding .. I already Implemented this thing with the help of this link Link With Implementation.
If you Still got any issue please let me know i already applied this in my application i will try to help you with code.
thanks

link publish delete flag offensive edit

answered 2012-09-12 09:15:01 +0800

davout gravatar image davout
1435 3 18

Thanks for the input, but I'd rather not go re-inventing features.

Can somebody from ZK confirm that this a bug?

link publish delete flag offensive edit

answered 2012-09-18 03:04:33 +0800

davout gravatar image davout
1435 3 18

Am I going to get a response from ZK to this question???

link publish delete flag offensive edit

answered 2012-09-18 03:32:33 +0800

davout gravatar image davout
1435 3 18

I've found a workaround...

Within the 'Messagebox.show' event handler have the code post a global command message to the MVVM class and have that new global command method force the list update. Like...

	public void deleteSelected() {
		Messagebox.show("Confirm deletion of selected entries?", "Confirm Dialog", Messagebox.OK | Messagebox.CANCEL,
				Messagebox.QUESTION, new org.zkoss.zk.ui.event.EventListener() {
					public void onEvent(Event evt) throws InterruptedException {
						if (evt.getName().equals("onOK")) {
							try {
								planEntityManager.delete(getSelectedProjectIDs());
								postGlobalCommand("resetGrid");
							}
							catch (PersistenceException e) {
								showErrorView(getCommand(), e);
							}
							catch (UnknownPlanEntityException e) {
								showErrorView(getCommand(), e);
							}

						}
					}
				});
	}

	@GlobalCommand("resetGrid")
	@NotifyChange({"projectModel","selectedProjects"})
	public void resetGrid() {
		setSelectedProjects(null);
		refreshModel();
	}

link publish delete flag offensive edit

answered 2012-09-20 08:51:15 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi Devout,

There is a related thread:
MVVM listbox selection problem with MessageBox

Regards,
Ben

link publish delete flag offensive edit

answered 2012-09-27 17:40:53 +0800

rickcr gravatar image rickcr
704 7

Ran into the same issue just now myself.

Opted for the posting of the GlobalCommand - which works but seems like their should be a cleaner approach.

link publish delete flag offensive edit

answered 2012-09-27 18:00:17 +0800

rickcr gravatar image rickcr
704 7

From a Java perspective I see how it could be challenging for the ZK team since that call (to reset grid) is in anonymous class.. it's not really in the View Model.

link publish delete flag offensive edit

answered 2012-10-25 15:20:03 +0800

zhvihti gravatar image zhvihti
12

As far as I know, Messagebox is asynchronous - it actions after your code has left the method. This is why @NotifyChange does not work. The reason your BindUtils call does not work is that you use "this" which is the anonymous class, rather than the VM.

What you are doing here is mixing the ViewModel with the ZUL. I think this is not optimal, and you should instead do it like the CRUD example: the CRUD example - basically have a variable hold the name of the file you want to delete, and the ZUL has a window that becomes visible when this variable is not null. Then you have the actual delete command bound to the "OK" button of the window.

link publish delete flag offensive edit

answered 2017-07-12 21:18:26 +0800

pahlito gravatar image pahlito
1

Maybe is't too late but anyway... the problem is the "this" object in BindUtils.postNotifyChange().

Since you're in a EventListener class, "this" is the EventListener and no your viewmodel.

To solve this you must create a final Object bean = this; in the method deleteSelected (outside the EventListener) and pass it to the BindUtils instead of 'this'.

I hope this helps someone.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-09-11 19:51:13 +0800

Seen: 451 times

Last updated: Apr 09 '20

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