Eclipse scout cache form page

127 views Asked by At

I want to cache state in form page when switching from page to page.

So : I have 3 page with forms and I want to data stays in forms when I switch from one to another.

I found this : 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();
  }
}

and says that setDetailForm() caches datas

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.

But this don't work for me.

My code is

@Override
protected void execPageActivated() throws ProcessingException {

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

    super.execPageActivated();
} 

but it stays on last page.

For example :

If I have page A,B,C and I open page A it create it self and set it to detailForm(). If I then open page B it is OK too. But if I then click on page A again it check if the detailForm() is not null (and it is not) so it stays on page B (insted of going on page A)

EDIT :

I figure that getDetailForm() is returning the right form but apparently super.execPageActivated() don't work.

1

There are 1 answers

0
Marko Zadravec On BEST ANSWER

I found out what was wrong.

Problem is in DefaultPageChangeStrategy class in Scout. Method pageChanged() is like this :

@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);
  }
 }
}

And if it is activePage a AbstractPage (and not AbstractPageWithTable AbstractPageWithNode), detailForm is always null and this break behavior.

So solution is to change AbstractPage with AbstractPageWithNode and add line

setTableVisible(false);

This line is needed because if it's not the firs time launch page will not be presented. (nodePage.getInternalTable() is not null but it is empty so :

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

will present empty page.)