0

所以我在提交它时有这个按钮,有一些功能将被执行,并且需要从列表中删除选中的复选框。

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

       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 上没有发生同样的情况,即我希望从刷新的列表中删除选定的复选框.....请建议......

4

1 回答 1

1

来自ListView#setReuseItems()

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

因此,如果reuseItems是真的,那么在您更改removeAll列表视图上的模型调用时。

于 2012-07-26T14:30:41.043 回答