First time here? Check out the FAQ!
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); } } }
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(); }
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
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(); }
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.
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.
Asked: 2012-09-11 19:51:13 +0800
Seen: 451 times
Last updated: Apr 09 '20