0

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

所以:我有 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() 不起作用。

4

1 回答 1

0

我发现出了什么问题。

问题出DefaultPageChangeStrategy在 Scout 的课堂上。方法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);
  }
 }
}

如果它是activePageAbstractPage (而不是AbstractPageWithTable AbstractPageWithNode),detailForm则始终是null这种中断行为。

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

setTableVisible(false);

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

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

将显示空白页面。)

于 2014-12-01T12:08:26.180 回答