【问题标题】:Gwt sencha grid(requestfactory) not displaying data even when store has data即使商店有数据,Gwt sencha grid(requestfactory)也不显示数据
【发布时间】:2014-05-02 01:13:02
【问题描述】:

我有一个煎茶网格,它有一个请求工厂来提取数据。 我可以从服务器中提取数据,但它没有显示出来。

我需要能够从组合框中进行 2 个选择,然后单击一个按钮以重新加载网格。但它似乎不起作用。

这里是代码-

@Override
public Widget asWidget() {
    final ExplorerRequestFactory rf = GWT
            .create(ExplorerRequestFactory.class);
    rf.initialize(new SimpleEventBus());

    RequestFactoryProxy<FilterPagingLoadConfig, PagingLoadResult<FlowerProxy>> proxy = new RequestFactoryProxy<FilterPagingLoadConfig, PagingLoadResult<FlowerProxy>>() {
        @Override
        public void load(
                final FilterPagingLoadConfig loadConfig,
                final Receiver<? super PagingLoadResult<FlowerProxy>> receiver) {
            FlowerRequest req = rf.flowerRequest();
            List<SortInfo> sortInfo = createRequestSortInfo(req,
                    loadConfig.getSortInfo());

            req.getFlowers(vId, fId, loadConfig.getOffset(),
                    loadConfig.getLimit(), sortInfo).to(receiver);
            req.fire();

        }
    };
    loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<FlowerProxy>>(
            proxy) {
        @Override
        protected FilterPagingLoadConfig newLoadConfig() {
            return new FilterPagingLoadConfigBean();
        }
    };
    loader.setRemoteSort(true);

    FlowerProxyProperties props = GWT.create(FlowerProxyProperties.class);

    ListStore<FlowerProxy> store = new ListStore<FlowerProxy>(props.id());
    loader.addLoadHandler(new LoadResultListStoreBinding<FilterPagingLoadConfig, FlowerProxy, PagingLoadResult<FlowerProxy>>(
            store) {
        @Override
        public void onLoad(
                final LoadEvent<FilterPagingLoadConfig, PagingLoadResult<FlowerProxy>> event) {
            LOG.info("Loader:addloadHondaler");
            super.onLoad(event);

            view.getView().refresh(false);
            view.getView().layout();
//********Data successfully retrieved but does not populate the grid *********///
//**************************///
            LOG.info("onLoad size:" + view.getStore().size()); //Data is present
        }
    });

    final PagingToolBar toolBar = new PagingToolBar(50);
    toolBar.getElement().getStyle().setProperty("borderBottom", "none");
    toolBar.bind(loader);

    ColumnConfig<FlowerProxy, String> nameColumn = new ColumnConfig<FlowerProxy, String>(
            props.name(), 150, "Name");
    ColumnConfig<FlowerProxy, Date> dateColumn = new ColumnConfig<FlowerProxy, Date>(
            props.LastAccessDate(), 150, "Date");
    dateColumn.setCell(new DateCell(DateTimeFormat
            .getFormat(PredefinedFormat.DATE_SHORT)));

    List<ColumnConfig<FlowerProxy, ?>> l = new ArrayList<ColumnConfig<FlowerProxy, ?>>();
    l.add(nameColumn);
    l.add(dateColumn);

    ColumnModel<FlowerProxy> cm = new ColumnModel<FlowerProxy>(l);

    view = new Grid<FlowerProxy>(store, cm);
    view.getView().setForceFit(true);
    view.setLoadMask(true);
    view.setLoader(loader);

    // Create the filters, and hook them to the loader and grid
    GridFilters<FlowerProxy> filters = new GridFilters<FlowerProxy>(loader);
    filters.initPlugin(view);

    filters.addFilter(new DateFilter<FlowerProxy>(props.LastAccessDate()));
    filters.addFilter(new StringFilter<FlowerProxy>(props.name()));


    VerticalLayoutContainer con = new VerticalLayoutContainer();
    con.setBorders(true);
    con.setPixelSize(400, 300);
    con.add(view, new VerticalLayoutData(1, 1));
    con.add(toolBar, new VerticalLayoutData(1, -1));

    return con.asWidget();
}
     //********Call to this function should trigger a data pull and populate the grid ******///
    /****************/
    // Requestfactory call goes through, gets the data too but does not update the grid
public void reload(final String v, final String flower) {
    LOG.info("V=> " + v + "\tFlower=> " + flower);
    this.vId = v;
    this.fId = flower;
    LOG.info("Store size:" + view.getStore().size());
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            if (v != null && flower != null && v.length() > 0
                    && flower.length() > 0) {
                loader.load();
                LOG.info("Loader called");
            } 
        }
    });

}

任何想法我在这里缺少什么?

【问题讨论】:

    标签: gwt grid gxt requestfactory


    【解决方案1】:

    无法运行代码(因为您没有发布代理、服务器实体、服务代理(也称为请求)或服务实现,这有点难说,但至少我确实看到了一件事肯定是错误的,而其他事情可能会令人困惑。

    首先,每次调用时都从asWidget() 返回相同的实例。我猜测正在发生的一系列事件让您感到困惑:

    • 应用程序启动,创建了一个小部件实例,其中存在此​​asWidget 方法。在设置它的过程中,会创建一个存储,就像一个加载器一样,并将this.loader 分配给该加载器。小部件已添加到 dom。
    • 在某些时候,asWidget() 会被第二次调用。这会保留旧网格(从第一次调用开始),并创建一个新网格、一个新存储、一个新加载器(并分配给 this.loader),但可能不会对新网格做任何事情
    • 终于调用了reload。这有一个有效的加载器(新的,而不是旧的),调用服务器,填充新的存储,它在新的网格中绘制。但是,旧网格仍处于附加状态,因此永远不会显示数据。

    修复此问题后,您实际上不需要重写 LoadResultListStoreBinding 中的任何方法 - 基类会将项目添加到商店,并且商店将发出网格正在侦听的事件。

    【讨论】:

    • 是的,看起来我的网格或 Widget 类有两个实例。我正在使用 GIN,并且必须做一些荒谬的事情来创建多个实例。我想我也需要更清楚 asWidget() 。如果我让我的 Grid 对象静态,网格加载就好了。有一些问题我需要解决。感谢您的指点。一旦我有一个好的解决方案,我会更新。
    • 真正的解决方法是每次从 asWidget 返回相同的实例,假设 Gin 没有行为不端并制作此类的多个副本(应该是单例吗?)。为此,通常将构建逻辑移至构造函数,或保存对父级的引用(即con),并且仅在con 为空时构建。如果不为null,则表示已经构建,无需再次构建。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2015-04-02
    • 1970-01-01
    相关资源
    最近更新 更多