5

I have a number of stateful pages with some state for each page. For example each page has a form that was submitted.

How can I organize a menu with links to last versions of these stateful pages? Should I store anywhere (may be in the session) reference to appropriate object for each page? If I use

onClick() { setResponsePage(MyPage.class); }

than I lose the previous state of the page. I want to link to last state of the page.

Adrian Wragg
  • 7,311
  • 3
  • 26
  • 50
Yuriy Yudin
  • 123
  • 1
  • 3

3 Answers3

1

Each time the page is rendered store the page's id in the session.

int pageId = pageInstance.getPageId();

A list or stack data structure could be used to hold the identifiers.

You can implement the navigation menu using a repeater (RepeatingView or such) that creates a new link for each page id in the session.

In the link's click handler you can redirect the user as follows:

Page pageInstance = (Page) new PageProvider(pageId, null).getPageInstance();
setResponsePage(pageInstance);
iluwatar
  • 1,778
  • 1
  • 12
  • 22
0
pageId = this.getPageId(); // get current version of lets say a HomePage


//OnClick for Link
public void onClick()
      { 
        WebPage homePageInstance =
          (WebPage) new PageProvider(HomePage.pageId, null).getPageInstance();
        setResponsePage(homePageInstance);
      }
    });
Jenya Miachyn
  • 104
  • 1
  • 5
  • 2
    code is not self explanatory. Please add some explanation in your code that the question author will understand what your code is trying to solve. – rajuGT Oct 23 '15 at 18:22
0

I make it passing int previousId parameter via constructor :

@MountPath(value = "editSomethingPage")
public class TestPage extends WebPage {

int previousPageId = 0;

public TestPage(int previousPage) {
    super();
    this.previousPageId = previousPage;
}

@Override
protected void onInitialize() {
    super.onInitialize();
    add(new Link("goBack") {
        @Override
        public void onClick() {
            if (previousPageId != 0) {
                setResponsePage((Page) AuthenticatedWebSession.get().getPageManager().getPage(previousPageId));
            } else {
                setResponsePage(PreviousPage.class);
            }
        }
    });
  }
}

It prevents creation of new page instance and keeps all states of page made by user.

sanluck
  • 1,544
  • 1
  • 12
  • 22