为什么TextField中的setText不起作用?

时间:2015-02-24 06:07:21

标签: gwt gxt

为什么此方法不会保存新选择的类别。我的代码有问题吗?

catCon = new TextField();
rowEditing.addEditor(catConfig, catCon);

这是设置catCon的代码:

TextButton save = new TextButton("Save");
save.addSelectHandler(new SelectEvent.SelectHandler() {

            @Override
            public void onSelect(SelectEvent event) {

                selectedItems = new LinkedList<Short>();
                for (int i = 0; i < toCat.size(); i++) {
                    selectedItems.add(toCat.get(i).getIDCategory());
                }
                Collections.sort(selectedItems);
                newSelectedItems = selectedItems.toString().replace(",", "-").replace("[", "").replace("]", "").replace(" ", "");

                msg = new MessageBox("SELECTED ITEMSSSSSSSSS: " + selectedItems.size() + " " + newSelectedItems);;
                msg.show();
                catCon.setText(newSelectedItems);
                hide();
            }
});

这是保存提交更改的地方:

rowEditing.getSaveButton().addSelectHandler(new SelectEvent.SelectHandler() {

                @Override
                public void onSelect(SelectEvent event) {
                    store.commitChanges();

                    service.saveUserRights(store.get(index), new AsyncCallback<Boolean>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            msg = new MessageBox("Error", caught.getMessage());
                            msg.show();
                        }

                        @Override
                        public void onSuccess(Boolean result) {
                            if (result) {
                                msg = new MessageBox("Information", "Changes saved.");
                                msg.show();
                                service.getURListGrid(new AsyncCallback<List<UserRights>>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        MessageBox msg = new MessageBox("Error", caught.getMessage());
                                        msg.show();
                                    }

                                    @Override
                                    public void onSuccess(List<UserRights> result) {
                                        store = new ListStore<UserRights>(properties.idRight());
                                        store.addAll(result);
                                        grid.reconfigure(store, cm);
                                    }
                                });
                            } else {
                                msg = new MessageBox("Error", "Failed to save changes.");
                                msg.show();
                            }
                        }
                    });
                }
            });

当我要设置catCon时,不会有数据更改,但是当我手动输入类别时,会有一个更改。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

为了让我保存当前类别是获取商店的索引并将类别设置为newSelectedItem

store.get(index).setCategories(newSelectedItems);

我希望这对那些和我有同样问题的人有所帮助。