Class PageProvider
- java.lang.Object
-
- org.apache.wicket.core.request.handler.PageProvider
-
- All Implemented Interfaces:
Serializable
,IPageProvider
,IClusterable
- Direct Known Subclasses:
PageAndComponentProvider
public class PageProvider extends Object implements IPageProvider, IClusterable
Provides page instance for request handlers. Each of the constructors has just enough information to get existing or create new page instance. Requesting or creating page instance is deferred untilgetPageInstance()
is called.Purpose of this class is to reduce complexity of both
IRequestMapper
s andIRequestHandler
s.IRequestMapper
examines the URL, gathers all relevant information about the page in the URL (combination of page id, page class, page parameters and render count), createsPageProvider
object and creates aIRequestHandler
instance that can use thePageProvider
to access the page.Apart from simplifying
IRequestMapper
s andIRequestHandler
sPageProvider
also helps performance because creating or obtaining page fromIPageManager
is delayed until theIRequestHandler
actually requires the page.- Author:
- Matej Knopp
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PageProvider(Class<? extends IRequestablePage> pageClass)
Creates a new page provider object.PageProvider(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
Creates a new page provider object.PageProvider(Integer pageId, Class<? extends IRequestablePage> pageClass, Integer renderCount)
Creates a new page provider object.PageProvider(Integer pageId, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount)
Creates a new page provider object.PageProvider(Integer pageId, Integer renderCount)
Creates a new page provider object.PageProvider(IRequestablePage page)
Creates a new page provider object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
detach()
Detaches the page if it has been loaded (that means eitherPageProvider(IRequestablePage)
constructor has been used orgetPageInstance()
has been called).boolean
doesProvideNewPage()
Returns whether or not the page instance held by this provider has been instantiated by the provider.Class<? extends IRequestablePage>
getPageClass()
Returns class of the page.Integer
getPageId()
Returns the page id.IRequestablePage
getPageInstance()
Returns page instance specified by the constructor.PageParameters
getPageParameters()
ReturnsPageParameters
of the page.protected IPageSource
getPageSource()
Integer
getRenderCount()
Returns the number of times this page has been rendered.boolean
hasPageInstance()
If this provider returns existing page, regardless if it was already created by PageProvider itself or is or can be found in the data store.protected void
setPageParameters(PageParameters pageParameters)
void
setPageSource(IPageSource pageSource)
If thePageProvider
is used outside request thread (thread that does not have application instance assigned) it is necessary to specify aIPageSource
instance so thatPageProvider
knows how to get a page instance.String
toString()
boolean
wasExpired()
Returns whether the provided page was expired prior to this access.
-
-
-
Constructor Detail
-
PageProvider
public PageProvider(Integer pageId, Integer renderCount)
Creates a new page provider object. Upon calling ofgetPageInstance()
this provider will return page instance with specified id.- Parameters:
pageId
-renderCount
- optional argument
-
PageProvider
public PageProvider(Integer pageId, Class<? extends IRequestablePage> pageClass, Integer renderCount)
Creates a new page provider object. Upon calling ofgetPageInstance()
this provider will return page instance with specified id if it exists and it's class matches pageClass. If none of these is true new page instance will be created.- Parameters:
pageId
-pageClass
-renderCount
- optional argument
-
PageProvider
public PageProvider(Integer pageId, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount)
Creates a new page provider object. Upon calling ofgetPageInstance()
this provider will return page instance with specified id if it exists and it's class matches pageClass. If none of these is true new page instance will be created.- Parameters:
pageId
-pageClass
-pageParameters
-renderCount
- optional argument
-
PageProvider
public PageProvider(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
Creates a new page provider object. Upon calling ofgetPageInstance()
this provider will return new instance of page with specified class.- Parameters:
pageClass
-pageParameters
-
-
PageProvider
public PageProvider(Class<? extends IRequestablePage> pageClass)
Creates a new page provider object. Upon calling ofgetPageInstance()
this provider will return new instance of page with specified class.- Parameters:
pageClass
-
-
PageProvider
public PageProvider(IRequestablePage page)
Creates a new page provider object. Upon calling ofgetPageInstance()
this provider will return the given page instance.- Parameters:
page
-
-
-
Method Detail
-
getPageInstance
public IRequestablePage getPageInstance() throws PageExpiredException
Description copied from interface:IPageProvider
Returns page instance specified by the constructor.- Specified by:
getPageInstance
in interfaceIPageProvider
- Returns:
- page instance
- Throws:
PageExpiredException
- if the specified page could not have been found and the constructor used did not provide enough information to create new page instance
-
getPageParameters
public PageParameters getPageParameters() throws PageExpiredException
Description copied from interface:IPageProvider
ReturnsPageParameters
of the page.- Specified by:
getPageParameters
in interfaceIPageProvider
- Returns:
- page parameters
- Throws:
PageExpiredException
- if the specified page could not have been found and the constructor used did not provide enough information to create new page instance
-
hasPageInstance
public final boolean hasPageInstance()
If this provider returns existing page, regardless if it was already created by PageProvider itself or is or can be found in the data store. The only guarantee is that by callinggetPageInstance()
this provider will return an existing instance and no page will be created.- Specified by:
hasPageInstance
in interfaceIPageProvider
- Returns:
- if provides an existing page
-
doesProvideNewPage
public final boolean doesProvideNewPage()
Returns whether or not the page instance held by this provider has been instantiated by the provider.- Specified by:
doesProvideNewPage
in interfaceIPageProvider
- Returns:
true
iff the page instance held by this provider was instantiated by the provider
-
wasExpired
public boolean wasExpired()
Description copied from interface:IPageProvider
Returns whether the provided page was expired prior to this access.- Specified by:
wasExpired
in interfaceIPageProvider
- Returns:
true
if the page was created after its original instance expired.
-
getPageClass
public Class<? extends IRequestablePage> getPageClass() throws PageExpiredException
Description copied from interface:IPageProvider
Returns class of the page.- Specified by:
getPageClass
in interfaceIPageProvider
- Returns:
- page class
- Throws:
PageExpiredException
- if the specified page could not have been found and the constructor used did not provide enough information to create new page instance
-
getPageSource
protected IPageSource getPageSource()
-
detach
public void detach()
Detaches the page if it has been loaded (that means eitherPageProvider(IRequestablePage)
constructor has been used orgetPageInstance()
has been called).- Specified by:
detach
in interfaceIPageProvider
-
setPageSource
public void setPageSource(IPageSource pageSource)
If thePageProvider
is used outside request thread (thread that does not have application instance assigned) it is necessary to specify aIPageSource
instance so thatPageProvider
knows how to get a page instance.- Parameters:
pageSource
-
-
setPageParameters
protected void setPageParameters(PageParameters pageParameters)
- Parameters:
pageParameters
-
-
getPageId
public Integer getPageId()
Description copied from interface:IPageProvider
Returns the page id.- Specified by:
getPageId
in interfaceIPageProvider
- Returns:
- page id
-
getRenderCount
public Integer getRenderCount()
Description copied from interface:IPageProvider
Returns the number of times this page has been rendered.- Specified by:
getRenderCount
in interfaceIPageProvider
- Returns:
- the number of times this page has been rendered.
-
-