模型正在更新,但pageablelistview不能反映UI + wicket上的更改 [英] model is getting updated but pageablelistview not reflecting the change on UI + wicket

查看:92
本文介绍了模型正在更新,但pageablelistview不能反映UI + wicket上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在提交此按钮时将执行该功能,并且需要从列表中删除选中的复选框.

So I have this button on submitting it there is some functioning which will be performed and the selected checkbox needed to be removed from the list.

下面的代码段显示了该按钮的用法以及我为删除特定复选框选择所做的实现.

The piece of code below shows the usage of that button and the implementation I have done to remove the particular checkbox selection.

       Button resumeDrive = new AjaxButton("resume", driveSearchForm)
        /**
         * 
         */
        private static final long serialVersionUID = -7016746377299867219L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            log.info("envoking resume");
            target.addComponent(form);
            try {

                List<DashboardModel> list = (List<DashboardModel>) group.getDefaultModelObject();
                log.info("drives data : " + list);
                if (list != null) {
                    List<Long> drives = new ArrayList<Long>();
                    List<DashboardModel> drivesToRemove = new ArrayList<DashboardModel>();
                    for (DashboardModel drive : list) {
                        drives.add(drive.getExecutionUnitId());

                        drivesToRemove.add(drive);
                        log.info("drivesToRemove :" + drivesToRemove);
                    }
                    log.info("selected drive: " + drives);
                    if (drives.size() > 0) {
                        log.info("Execution Ids to resume : " + drives);

                        driveResumeService.resumeDrives(drives);
                        drivesData.removeAll(drivesToRemove);
                        log.info("drivesdata :" + drivesData);

                        warn("Execution Ids to resume : " + drives);
                    } else {
                        warn("No drives selected for resuming.");
                    }
                } else {
                    info("No drives to resume.");
                }
            } catch (Exception e) {
                warn("Failed to resume jobs. " + e.getMessage());
                log.info("Failed to resume jobs", e);
            }
            target.addComponent(group);
        }
        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(form);
        }
            driveSearchForm.add(resumeDrive);
    resumeDrive.setDefaultFormProcessing(true);
    resumeDrive.add(new AjaxFormValidatingBehavior(driveSearchForm, "onClick"));

--> my model returns this driveData.
    --->   I'm sticking the pageableListView code also alongside.

            private CheckGroup<DashboardModel> group;
            group = new CheckGroup<DashboardModel>("group", new ArrayList<DashboardModel>());
    driveSearchForm.add(group);
    group.add(new CheckGroupSelector("allSelected"));
    group.setOutputMarkupId(true);

     pageableListView = new PageableListView<DashboardModel>("searchResults", driveDataModel, 10) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<DashboardModel> item) {
            item.add(new Check("check", item.getModel()));
            item.add(new Label("name", item.getModelObject().getName()));
            item.add(new Label("status", item.getModelObject().getStatus().toString()));
            item.add(new Label("driveUrl", item.getModelObject().getDriveURL()));
        }

    };
    pageableListView.setRenderBodyOnly(false);
    pageableListView.setReuseItems(true);
    group.add(pageableListView);
    group.add(new PagingNavigator("navigator", pageableListView));

所以我发现我的模型正在更新,但是在UI上却没有发生同样的事情,即 我希望将选定的复选框从刷新列表中删除. 请建议......

So I found that my models are getting updated but the same is not happening on the UI i.e. I want the selected checkboxes to be removed from the refreshed list..... Please suggest......

推荐答案

来自ListView#setReuseItems():

但是,如果您修改listView模型对象,则必须手动调用listView.removeAll()才能重建ListItems.

But if you modify the listView model object, than you must manually call listView.removeAll() in order to rebuild the ListItems.

因此,如果reuseItems为true,则在更改模型时,将在列表视图上调用removeAll.

So if reuseItems is true, then at the point where you change your model call removeAll on the listview.

这篇关于模型正在更新,但pageablelistview不能反映UI + wicket上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆