Link to last version of stateful page

351 views Asked by At

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.

3

There are 3 answers

0
iluwatar On

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);
1
Jenya Miachyn On
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);
      }
    });
0
sanluck On

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.