0

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.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
  • I do not manage to reproduce the problem in my workspace. I have a breakpoint in execPageActivated(). The first time I click on the page, getDetailForm() is null, the form is instanciated. I click somewhere else. After that when I come on the same page again, getDetailForm() is not null and the previous instanciated form (corresponding to this page instance) is displayed again. What do you mean by "it refresh form every time that page is activated". – Jmini Nov 14 '14 at 10:15
  • I Edit my question. It seems that previous behaviour was due to not starting my server again. – Marko Zadravec Nov 17 '14 at 05:56
  • Have you a stacktrace or something like that in the client console log? – Jmini Nov 18 '14 at 07:50
  • No, because there is no error reported. – Marko Zadravec Nov 18 '14 at 12:06
  • Does `super.execPageActivated()` correspond to `AbstractPageWithNodes#execPageActivated()` or to `AbstractPage#execPageActivated()` which is empty. I still do not manage to understand what is going on in your code. – Jmini Nov 18 '14 at 13:20
  • AbstractPage#execPageActivated() which is empty. Problem is that if I set code as is on example, then switching page is not working. If I open page A and then page B and then page C, then if you try to open page C it won't work. – Marko Zadravec Nov 18 '14 at 14:56

1 Answers1

0

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.)

Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97