public interface PageFactory
Page for a page key.
An application implements this interface once and supplies the single instance to
Navigator.initialize(ej.mwt.Desktop, PageFactory). The navigator calls
create(int, Object) only when a navigation pushes a new history entry or replaces the
active one — that is, from Navigator.navigateTo(int) and
Navigator.replaceWith(int). Back navigations
(Navigator.navigateBack() and Navigator.navigateBackTo(int)) never call it: they
re-show the Page instance the navigator cached in its history, so a page's fields survive a
round trip through back navigation.
The factory is where per-navigation data is injected. Along with the key, it receives the argument
the navigation carried — the one given to Navigator.navigateTo(int, Object) or
Navigator.replaceWith(int, Object), and null for the overloads that carry none
— and passes it to the page's own constructor. The navigator keeps no reference to that
argument and imposes no parameter slot on Page, so the page decides what it stores and in
which type.
The navigator is not passed to create(int, Object): a factory, or a page it builds, reaches
it with Navigator.getInstance(), so a page can trigger navigation without a separately wired
back-reference.
| Modifier and Type | Method and Description |
|---|---|
Page |
create(int key,
Object argument)
Creates the page identified by the given key, injecting the given per-navigation argument.
|
Page create(int key, @Nullable Object argument) throws IllegalArgumentException
Called by the navigator when a navigation pushes a new history entry
(Navigator.navigateTo(int)) or replaces the active one
(Navigator.replaceWith(int)); it is not called on back navigation, which re-shows the
cached page. A fresh page is expected on each call; the returned page must not be null.
The argument is the one the navigation carried, and is null when it carried none. A
factory that resolves a key expecting an argument is responsible for checking what it received:
the navigator neither inspects the argument nor matches it against the key.
key - the non-negative key of the page to create.argument - the argument the navigation carried, or null if it carried none.IllegalArgumentException - if the given key does not identify any page.