1

我成功地从列表框中删除了选定的项目,然后从数据库中删除了所有对象并刷新了列表框。然后我添加了带有是和否选项的确认框,然后我的列表没有刷新。我在 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。

提前致谢。

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

 @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, "*");

    }
4

1 回答 1

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("*")

删除记录后,您还需要在此处从列表中删除对象...

于 2013-03-21T12:43:49.003 回答