mercredi 30 août 2017

How to get objects from ListStore?

I am working on some GWT app. I have two classes: GwtRole and GwtAccessRole. GwtRole are all available roles in application, while GwtAccessRoles are roles which are assigned to selected user via checkbox form panel. When user clicks on button for adding some roles, then checkbox form panel appears with all available roles(GwtRoles are all roles which exist in application). But I want to set that when user clicks on button and checkbox form panel shows, then roles which are already in database to be automatically checked. I have a list of roles which are in database(GwtAccessRoles are roles which are selected in checkbox and stored in db) via RpcProxy method, but I dont know how to get that roles from ListStore. This is my code for checkbox form panel with all available roles:

 CheckBoxSelectionModel<GwtRole> selectionModel = new CheckBoxSelectionModel<GwtRole>();

        configs.add(selectionModel.getColumn());
        RpcProxy<ListLoadResult<GwtRole>> roleUserProxy = new RpcProxy<ListLoadResult<GwtRole>>() {

            @Override
            protected void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtRole>> callback) {
                GWT_ROLE_SERVICE.findAll(currentSession.getSelectedAccount().getId(),
                        callback);
            }
        };

        BaseListLoader<ListLoadResult<GwtRole>> roleLoader = new BaseListLoader<ListLoadResult<GwtRole>>(roleUserProxy);
        roleLoader.load();
        ListStore<GwtRole> roleStore = new ListStore<GwtRole>(roleLoader);

        aa = new CheckBoxListView<GwtRole>() {

            @Override
            protected GwtRole prepareData(GwtRole model) {
                String name = model.getName();
                model.set("name", name);
                return model;
            };
        };
         aa.setStore(roleStore);
         aa.setDisplayProperty("name");

roleFormPanel.add(aa);

        bodyPanel.add(roleFormPanel);

and when user click on button, checkbox form panel with names of all available roles appears. This is my method for finding all roles which are in database already(those which are selected last time):

     RpcProxy<PagingLoadResult<GwtAccessRole>> proxy = new RpcProxy<PagingLoadResult<GwtAccessRole>>() {

                @Override
                protected void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtAccessRole>> callback) {
                    GWT_ACCESS_ROLE_SERVICE.findByUserId((PagingLoadConfig) loadConfig, currentSession.getSelectedAccount().getId(), userId, callback);

                }
            };
            BasePagingLoader<PagingLoadResult<GwtAccessRole>> loader = new BasePagingLoader<PagingLoadResult<GwtAccessRole>>(proxy);
            loader.load();
 ListStore<GwtAccessRole> accessRoleStore = new ListStore<GwtAccessRole>(loader);

I dont know how to get objects from this accessRoleStore to set that all items(from all available roles) which have same id like items from this list to be checked automatically. I am sure that this method gives me real values, because I tested it(I changed that checkbox form panel shows me roles from this method and its all ok) but when I try to get values nothing happens. I found that I should do that with accessRoleStore.getModels() but that gives me 0. Does someone have idea how to get list of objects from those two listStores?




Aucun commentaire:

Enregistrer un commentaire