zk:确认框后,页面刷新问题,活页夹无效

时间:2013-03-21 12:32:50

标签: java mvvm zk

我成功删除了列表框中的所选项目,之后所有对象都从db中删除,并且列表框已刷新。 然后我添加了是和没有选项的确认框,然后我的列表没有刷新。我在zk论坛上用一个解决方案看到了这个类似问题的线程,我实现了它但得到了类转换异常

我正在使用MVVM

http://forum.zkoss.org/question/73640/refreshing-listbox-after-deleting-an-itemrow/

代码获取异常:

AnnotateDataBinder binder = (AnnotateDataBinder) userWin.getAttribute("binder");
                    binder.loadAll();

异常:

Mar 21, 2013 5:22:23 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1352
SEVERE: >>java.lang.ClassCastException: org.zkoss.bind.AnnotateBinder cannot be cast to org.zkoss.zkplus.databind.AnnotateDataBinder
期待收到你的来信。我搜索过网,但除了更新zk之外找不到任何东西。我已经在使用最新版本的zk 6.5.1.1。

提前感谢。

@after添加你建议的代码行,我的列表没有更新,这是我的方法

 @Override
    @Command("deleteAllSelected")
    @NotifyChange({"selectedObject","objectList"})
    public void deleteAllSelected() {
        logger.info("in deleteAllSelected()>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        logger.info("direct selection: " + objectList.getSelection());
        final Set<UserIntelliopsDTO> setMe = objectList.getSelection();
        logger.info("selectedion size in dellete all" + setMe.size());



        EventListener<ClickEvent> clickListener = new EventListener<Messagebox.ClickEvent>() {
            public void onEvent(ClickEvent event) throws Exception {
                if (Messagebox.Button.YES.equals(event.getButton())) {
                    int i =0;
                    for(UserIntelliopsDTO dto:setMe){

                        userService.deleteUserIntelliops(dto.getUserIntelliOps().getUserId());

                        logger.info("siapa:userIntelliops " + dto.getUserIntelliOps() +  dto.getUserIntelliOps().getUserId());
                        selectedObject = null;

                        logger.info("iteration: " + i);
                        ++i;
                    }

                    selectedObject = null;
                    deleteAllSelectedButton.setVisible(false);
                    enableEditMode(true);


                }
            }
        };
        Messagebox.show("Are you sure you want to delete all selected records?", "Delete All Selected",
                new Messagebox.Button[] { Messagebox.Button.YES,
                        Messagebox.Button.NO }, Messagebox.QUESTION,
                clickListener);


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

    }

1 个答案:

答案 0 :(得分:4)

我假设您正在使用MVVM模型。所以当您点击下面的删除按钮时,您可以执行此操作将代码...

 @Command
public void doDeleteItems(@ContextParam(ContextType.VIEW) Component view) {
        logger.debug("Delete Icon selected");

if (myModel.getSelectedListItem() == null || myModel.getSelectedListItem().isEmpty()) {
            showError("No rows are selected");
        } else {

Messagebox.show("Are you sure you want to delete?", "Alert !!", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION,new org.zkoss.zk.ui.event.EventListener() {

public void onEvent(Event evt) throws InterruptedException {
    if (evt.getName().equals("onYes")) {
//Add code for Deletion
  if (listModel.contains(deletedObj))
listModel.remove(deletedObj); 
}
else{
//Do somthing else
}
BindUtils.postNotifyChange(null, null, this, "*");//this means current viewmodel object and refresh the variables

}

正如我BindUtils.postNotifyChange()那样,它会为您刷新列表做出魔力,或者您可以使用NotifyChange("*")

此处还有一件事需要在删除记录后从列表中删除对象...