Class PageProvider
- java.lang.Object
-
- org.apache.wicket.core.request.handler.PageProvider
-
- All Implemented Interfaces:
java.io.Serializable,IPageProvider,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
PageAndComponentProvider
public class PageProvider extends java.lang.Object implements IPageProvider, org.apache.wicket.util.io.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
IRequestMappers andIRequestHandlers.IRequestMapperexamines the URL, gathers all relevant information about the page in the URL (combination of page id, page class, page parameters and render count), createsPageProviderobject and creates aIRequestHandlerinstance that can use thePageProviderto access the page.Apart from simplifying
IRequestMappers andIRequestHandlersPageProvideralso helps performance because creating or obtaining page fromIPageManageris delayed until theIRequestHandleractually requires the page.- Author:
- Matej Knopp
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PageProvider(java.lang.Class<? extends IRequestablePage> pageClass)Creates a new page provider object.PageProvider(java.lang.Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters pageParameters)Creates a new page provider object.PageProvider(java.lang.Integer pageId, java.lang.Class<? extends IRequestablePage> pageClass, java.lang.Integer renderCount)Creates a new page provider object.PageProvider(java.lang.Integer pageId, java.lang.Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters pageParameters, java.lang.Integer renderCount)Creates a new page provider object.PageProvider(java.lang.Integer pageId, java.lang.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 voiddetach()Detaches the page if it has been loaded (that means eitherPageProvider(IRequestablePage)constructor has been used orgetPageInstance()has been called).booleandoesProvideNewPage()Returns whether or not the page instance held by this provider has been instantiated by the provider.java.lang.Class<? extends IRequestablePage>getPageClass()Returns class of the page.java.lang.IntegergetPageId()Returns the page id.IRequestablePagegetPageInstance()Returns page instance specified by the constructor.org.apache.wicket.request.mapper.parameter.PageParametersgetPageParameters()ReturnsPageParametersof the page.protected IPageSourcegetPageSource()java.lang.IntegergetRenderCount()Returns the number of times this page has been rendered.booleanhasPageInstance()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 voidsetPageParameters(org.apache.wicket.request.mapper.parameter.PageParameters pageParameters)voidsetPageSource(IPageSource pageSource)If thePageProvideris used outside request thread (thread that does not have application instance assigned) it is necessary to specify aIPageSourceinstance so thatPageProviderknows how to get a page instance.java.lang.StringtoString()booleanwasExpired()Returns whether the provided page was expired prior to this access.
-
-
-
Constructor Detail
-
PageProvider
public PageProvider(java.lang.Integer pageId, java.lang.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(java.lang.Integer pageId, java.lang.Class<? extends IRequestablePage> pageClass, java.lang.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(java.lang.Integer pageId, java.lang.Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters pageParameters, java.lang.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(java.lang.Class<? extends IRequestablePage> pageClass, org.apache.wicket.request.mapper.parameter.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(java.lang.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:IPageProviderReturns page instance specified by the constructor.- Specified by:
getPageInstancein 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 org.apache.wicket.request.mapper.parameter.PageParameters getPageParameters() throws PageExpiredExceptionDescription copied from interface:IPageProviderReturnsPageParametersof the page.- Specified by:
getPageParametersin 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:
hasPageInstancein 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:
doesProvideNewPagein interfaceIPageProvider- Returns:
trueiff the page instance held by this provider was instantiated by the provider
-
wasExpired
public boolean wasExpired()
Description copied from interface:IPageProviderReturns whether the provided page was expired prior to this access.- Specified by:
wasExpiredin interfaceIPageProvider- Returns:
true>if the page was created after its original instance expired.
-
getPageClass
public java.lang.Class<? extends IRequestablePage> getPageClass() throws PageExpiredException
Description copied from interface:IPageProviderReturns class of the page.- Specified by:
getPageClassin 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:
detachin interfaceIPageProvider
-
setPageSource
public void setPageSource(IPageSource pageSource)
If thePageProvideris used outside request thread (thread that does not have application instance assigned) it is necessary to specify aIPageSourceinstance so thatPageProviderknows how to get a page instance.- Parameters:
pageSource-
-
setPageParameters
protected void setPageParameters(org.apache.wicket.request.mapper.parameter.PageParameters pageParameters)
- Parameters:
pageParameters-
-
getPageId
public java.lang.Integer getPageId()
Description copied from interface:IPageProviderReturns the page id.- Specified by:
getPageIdin interfaceIPageProvider- Returns:
- page id
-
getRenderCount
public java.lang.Integer getRenderCount()
Description copied from interface:IPageProviderReturns the number of times this page has been rendered.- Specified by:
getRenderCountin interfaceIPageProvider- Returns:
- the number of times this page has been rendered.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-