model is getting updated but pageablelistview not reflecting the change on UI + wicket

。_饼干妹妹 提交于 2019-12-13 06:05:32

问题


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));

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......


回答1:


From ListView#setReuseItems():

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

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



来源:https://stackoverflow.com/questions/11668683/model-is-getting-updated-but-pageablelistview-not-reflecting-the-change-on-ui

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