GXT - 网格不反映变化

时间:2015-05-21 19:12:27

标签: gwt gxt

请您查看下面的代码,看看它有什么问题。问题是加载数据时网格中没有数据出现。所有类都在下面(我只发布与失败功能相关的应用程序部分):

ItemGrid(该类表示通过feedService.loadItems(asyncCallback)呈现数据的网格)

public class ItemGrid extends LayoutContainer {

    public ItemGrid() {
        setLayout(new FitLayout());
    }

    @Override
    protected void onRender(Element parent, int index) {
        super.onRender(parent, index);
        final List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
        columns.add(new ColumnConfig("title", "Title", 200));
        columns.add(new ColumnConfig("description", "Description", 200));

        final ColumnModel columnModel = new ColumnModel(columns);
        final FeedServiceAsync feedService = Registry.get(RSSReaderConstant.FEED_SERVICE);
        RpcProxy<List<Item>> proxy = new RpcProxy<List<Item>>(){
            @Override
            protected void load(Object o, AsyncCallback<List<Item>> asyncCallback) {
                feedService.loadItems(asyncCallback);
            }
        };
        ListLoader<ListLoadResult<Item>> loader = new BaseListLoader<ListLoadResult<Item>>(proxy);
        ListStore<ModelData> itemStore = new ListStore<ModelData>(loader);

        List<ModelData> modelDataList = itemStore.getModels();
        for (ModelData model : modelDataList) {
            System.out.println("I got that point");
            Map<String, Object> modelMap = model.getProperties();
            Set<String> keys = modelMap.keySet();
            for (String key : keys) {
                System.out.println("Key is " + key);
            }
        }

        Grid<ModelData> grid = new Grid<ModelData>(itemStore, columnModel);
        grid.setBorders(true);
        grid.setAutoExpandColumn("description");
        loader.load();
        add(grid);
    }
}

RssMainPanel(网格所在的容器)

public class RssMainPanel extends ContentPanel {

    public RssMainPanel(String label) {
        setHeadingText(label);
        setLayout(new FitLayout());
        add(new ItemGrid());
    }
}

Item.class(代表实体的类)

public class Item extends BaseModel implements IsSerializable {

    private String cathegory;
    private String description;
    private String link;
    private String title;

    public String getCathegory() {
        return cathegory;
    }

    public void setCathegory(String cathegory) {
        this.cathegory = cathegory;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

我希望这部分代码足够了。我知道这可能是一个简单的问题,但我是GWT / GXT的新手并且遇到了问题。我会很感激任何反馈。

1 个答案:

答案 0 :(得分:0)

我发现了问题(坦率地说,我不明白为什么这可能是个问题)。问题出在Item-entity中。我实现了BeanModelTag(而不是扩展BaseModel),在BaseListLoader<ListLoadResult<Item>>(proxy, reader)中传递BeanModelReader作为参数,然后就可以了。但我仍然没有理解为什么扩展BaseModel会导致数据传输失败。