Is it possible use @NotifyChange instead of BindUtils.postNotifyChange?

旧街凉风 提交于 2019-12-07 16:36:07

问题


I have one confusion use between @NotifyChange and BindUtils.postNotifyChange ,Why use this two event .Before i read this question In ZK Can we PostNotifyChange more than one variables . But i cant understand this question why use this more than one variable.

Here's an example:

    @Command
    @NotifyChange({ "folderInfoList", "isDisabled", "selectedFolderInfo" })
    public void refreshFolderInfo() {
        logger.debug("Refresh Icon selected");
        if (isDirty()) {
            Messagebox.show(pageResourceBundle.getText("JS_CONFIRM_DATAMODIFED"), pageResourceBundle.getText("JS_CONFIRM_DATAMODIFED_TYPE"),
                    Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, new EventListener<Event>() {
                        public void onEvent(Event event) throws Exception {
                            if (Messagebox.ON_OK.equals(event.getName())) {
                                loadFolderInfoList();
                                selectedFolderInfo = null;
                                BindUtils.postNotifyChange(null, null, FolderInfoEditViewModel.this, "folderInfoList");
                            } else {

                            }
                        }
                    });
        } else {
            loadFolderInfoList();
            selectedFolderInfo = null;
        }
    }

Can anybody tell me:

I have four question :

1.Why use isDisabled in @NotifyChange ?

2.Here this method i can use @NotifyChange instead of BindUtils.postNotifyChange ?

3.What is the difference between @NotifyChange and BindUtils.postNotifyChange ?

4.I want to use only one event between this two @NotifyChange and BindUtils.postNotifyChange in method .Is it possible for this method ?


回答1:


1) If the variable associated with "isDisabled" is not changed in any case by this call, you don't need to.
But maybe it is changed inside loadFolderInfoList()
2) You can imagine that a @NotifyChange({"arg1","arg2",...,"argN"}) is the same as

for(String arg : args){ 
  BindUtils.postNotifyChange(null, null, refToClassCalledFrom, arg); 
}

3) But you can call BindUtils.postNotifyChange(...) from everywhere as long as you got a reference to the VM.
4) To me it looks like this code is from a nested class of FolderInfoEditViewModel, that it self is is VM as well as FolderInfoEditViewModel.
In this case the @NotifyChage(...) is invoked for the nested class but

BindUtils.postNotifyChange(null, null, FolderInfoEditViewModel.this, "folderInfoList");

refers to it's outer class FolderInfoEditViewModel and that can only be archived this way.



来源:https://stackoverflow.com/questions/19977102/is-it-possible-use-notifychange-instead-of-bindutils-postnotifychange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!