Ok Anthony.
I suggest the scope attribute in the @Page annotation:
@Page(scope="session")
Theoretically, possible scopes could be:
- visible
- window
- session
- application
Visible scope would be the default value and means, “the page currently visible”. That’s how Nav7 works now. It would set the page in no explicit cache, it’s just in the current Vaadin Window.
Window scope would be bound to the open tab. If a user comes back on a page from that tab, we would reuse the stored instance. Don’t know if this level would be useful. This corresponds to the Vaadin “Window” notion.
Session scope would be bound to the HttpSession, wich is currently named “Application” in Vaadin. It would be for that user, all tabs and browser windows shared (hope they will rename Window, Application & co in version 7).
Application scope would be the ServletContext. It would be a page reused for all users (as a home page for example).
The last 2 levels (Session and Application) would require changes in the Vaadin structure as because now a Page is a Component inside one (and only one) Window.
We’d also need the timeout attribute.
@Page(timeout=60*60*2) // 2 hours
It would be the amount of seconds for keeping that page in cache without renewing (reinstantiating) it.
As implementation, of the “window” scope, I would probably change PageInvocation.getPageInstance() method.
public synchronized Component getPageInstance() {
if (pageInstance == null) {
try {
// instantiate page like: auctionPage = new AuctionPage();
pageInstance = (Component) pageClass.newInstance();
isInstanceNew = true;
} catch (Exception e) {
RuntimeException e2 = new RuntimeException("Problem while instantiating page class ["+pageClass+"]
. Probably bug. Does your page class have a no-arg constructor?", e);
placeExceptionPage(e2);
throw e2;
}
}
return pageInstance;
}
In the if pageInstance == null, I’d start with looking for the page in the cache.
We’d probably need a new PageCache class to manage the caching.
It would have a method “getPage(Class<? extends Component)” that returns a page or null.
The getPage method would look in the NavigableAppLevelWindow instance (getCurrent). NavigableAppLevelWindow would have a Map<Class<? extends Component>, DateAndComponent> cachedPages with the cached pages.
DateAndComponent would be a public static inner class of PageClass just holding a Date and Component value (2 attributes) together. Date is needed for the timeout.
We’d probably need to manage the page.getParent() attribute also. Only one page at a time can be NavigableAppLevelWindow.pageContainer at a time (=> not all the pages of the cache…)
Any volounteer to implement that?
I’ll be happy to review the code. Start from the SVN repository (v7.48).
John.