【问题标题】:Eclipse scout cache form pageEclipse Scout 缓存表单页面
【发布时间】:2015-11-26 11:15:29
【问题描述】:

当从一个页面切换到另一个页面时,我想在表单页面中缓存状态。

所以:我有 3 页的表单,当我从一个表单切换到另一个表单时,我希望数据保留在表单中。

我发现了这个:https://wiki.eclipse.org/Scout/Concepts/Page_Detail_Form

@Override
protected void execPageActivated() throws ProcessingException {
  if (getDetailForm() == null) {
    PersonDetailForm form = new PersonDetailForm();
    form.setPersonNr(getPersonNr());
    setDetailForm(form);
    form.startView();
  }
}

并说 setDetailForm() 缓存数据

As already said, attaching a detail form to a page means the detail form will automatically be 
hidden when the page gets deactivated and shown when the page gets activated (see 
PageDetailFormChanged on Desktop). So the detail form actually gets cached and does not need to 
be started more than once per page. This requires that the form does not get closed.

但这对我不起作用。

我的代码是

@Override
protected void execPageActivated() throws ProcessingException {

    // / Create and open form
    if (getDetailForm() == null) {
      MarginCalculationForm form = new MarginCalculationForm();
      form.startModify();
      setDetailForm(form);
    }

    super.execPageActivated();
} 

但它停留在最后一页。

例如:

如果我有页面 A、B、C,并且我打开页面 A,它会自行创建并将其设置为 detailForm()。如果我然后打开页面 B 也可以。但是,如果我然后再次单击页面 A,它会检查 detailForm() 是否不为空(并且它不是),因此它会停留在页面 B 上(进入页面 A)

编辑:

我认为 getDetailForm() 正在返回正确的表单,但显然 super.execPageActivated() 不起作用。

【问题讨论】:

  • 我无法在我的工作区重现该问题。我在 execPageActivated() 中有一个断点。第一次点击页面,getDetailForm()为null,窗体实例化。我点击其他地方。之后,当我再次进入同一页面时,getDetailForm() 不为空,并且再次显示先前实例化的表单(对应于此页面实例)。 “每次激活该页面时都会刷新表单”是什么意思。
  • 我编辑我的问题。以前的行为似乎是由于没有再次启动我的服务器。
  • 在客户端控制台日志中是否有堆栈跟踪或类似内容?
  • 否,因为没有报错。
  • super.execPageActivated() 对应于AbstractPageWithNodes#execPageActivated() 还是对应于空的AbstractPage#execPageActivated()。我仍然无法理解您的代码中发生了什么。

标签: forms eclipse-scout


【解决方案1】:

我发现了问题所在。

问题出在 Scout 的 DefaultPageChangeStrategy 类中。方法pageChanged()是这样的:

@Override
public void pageChanged(IOutline outline, IPage deselectedPage, IPage selectedPage) {
  if (outline == null) {
    return;
  }

  outline.clearContextPage();
  IForm detailForm = null;
  ITable detailTable = null;
  ISearchForm searchForm = null;
  // new active page
  outline.makeActivePageToContextPage();
  IPage activePage = outline.getActivePage();
  if (activePage != null) {
    try {
      activePage.ensureChildrenLoaded();
    }
    catch (ProcessingException e1) {
      SERVICES.getService(IExceptionHandlerService.class).handleException(e1);
    }
    if (activePage instanceof IPageWithTable) {
      IPageWithTable tablePage = (IPageWithTable) activePage;
      detailForm = activePage.getDetailForm();
      if (activePage.isTableVisible()) {
        detailTable = tablePage.getTable();
      }
      if (tablePage.isSearchActive()) {
        searchForm = tablePage.getSearchFormInternal();
      }
    }
    else if (activePage instanceof IPageWithNodes) {
      IPageWithNodes nodePage = (IPageWithNodes) activePage;
      detailForm = activePage.getDetailForm();
      if (activePage.isTableVisible()) {
        detailTable = nodePage.getInternalTable();
      }
    }
  }

  // remove first
  if (detailForm == null) {
    outline.setDetailForm(null);
  }
  if (detailTable == null) {
    outline.setDetailTable(null);
  }
  if (searchForm == null) {
    outline.setSearchForm(null);
  }
  // add new
  if (detailForm != null) {
    outline.setDetailForm(detailForm);
  }
  if (detailTable != null) {
    outline.setDetailTable(detailTable);
  }
  if (searchForm != null) {
    outline.setSearchForm(searchForm);
  }
 }
}

如果它是 activePage 一个 AbstractPage(而不是 AbstractPageWithTable AbstractPageWithNode),detailForm 始终是 null 并且这种中断行为。

所以解决方案是用 AbstractPageWithNode 更改 AbstractPage 并添加行

setTableVisible(false);

需要此行,因为如果不是第一次,则不会显示启动页面。 (nodePage.getInternalTable() 不为空,但为空,所以:

  if (detailTable != null) {
    outline.setDetailTable(detailTable);
  }

将显示空白页面。)

【讨论】:

    猜你喜欢
    • 2015-04-28
    • 1970-01-01
    • 2016-07-24
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多