【问题标题】:How can i get the edited proxy from RequestFactoryEditorDriver如何从 RequestFactory Editor Driver 获取编辑后的代理
【发布时间】:2011-06-09 21:55:04
【问题描述】:

在使用编辑器进行更改后,我不知道如何更新我的单元格表。如果我可以获得编辑后的代理,那么我可以使用 dataprovider 来更新我的 celltable。

public void saveCampaign() {
  driver.flush();
  // the problem. proxy at this point should have the new values?....
  context.persist().using(proxy).fire(new Receiver<Void>() {
    @Override
    public void onSuccess(Void response) {
      showListView();
    }
  });
}

.using(proxy) 中的代理不包含在编辑器上所做的更改。但是,服务器上的 persist 方法获取更新的值。如果我从服务器重新加载数据,我会在单元表中获得正确的值。

public void editCampaign(CampaignProxy proxy) {
  this.proxy = proxy;
  if (proxy != null) {
    context = AEHOME.requestFactory.campaignRequest();
    showEditView();
  }
}

private void showEditView() {
  driver.initialize(eventBus, AEHOME.requestFactory, editView);
  driver.edit(proxy, context);
  deckPanel.showWidget(deckPanel.getWidgetIndex(editView));
}

在列表视图中设置代理:configurationPageView.proxy = selectionModel.getSelectedObject();

任何建议将不胜感激。谢谢你。

【问题讨论】:

    标签: gwt requestfactory


    【解决方案1】:

    您可以通过执行以下操作来更改构建请求的方式:

    private void showEditView() {
      driver.initialize(eventBus, AEHOME.requestFactory, editView);
      driver.edit(proxy, context);
      // Set up method invocation and callback in advance
      context.persist().using(proxy).to(new Receiver<Void>() {
        @Override
        public void onSuccess(Void response) {
          showListView();
        }
      }););
      deckPanel.showWidget(deckPanel.getWidgetIndex(editView));
    }
    
    public void saveCampaign() {
      driver.flush().fire();
    }
    

    在 GWT 2.4 中,可以保留您当前的代码组织并使用RequestContext.append():

    public void saveCampaign() {
      // Returns the context passed to edit()
      RequestContext ctx = driver.flush();
      // append() is generic and returns the type returned by myProxyContext();
      ctx.append(requestFactory.myProxyContext()).persist().using(proxy).fire(....);
    }
    

    【讨论】:

    • 感谢您的出色回复。我现在有了更好的理解。我仍然无法获得对 editProxy 的引用来更新我的 celltable。我试图从 persist 方法返回新代理,但这破坏了 ReqeustFactory 接口。我期待 celltable 自动更新。在单元表显示的代理中发生编辑后更新单元表的好方法是什么? onSuccess(无效响应){ proxy.getAdTitle(); // 此时代理具有旧值 showListView(); }
    • 更新 UI 最可靠的方法是让您的 UI 元素从共享的 EventBus 监听 EntityProxyChange 事件。当 UI 元素收到它关心的实体已更新的通知时,它应该创建自己的RequestFactory.find()(因为该事件仅包含一个 id)来检索它需要的数据。这种解耦有助于减少代码中关注点之间的交叉连接量。在 GWT 2.4 中,使用 RequestBatcher.get().find() 会提高效率。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多