Interface Page
- All Superinterfaces:
PageLifecycleCallbackHub
- All Known Implementing Classes:
PageImpl
Represents a unique page within the application. Pages are part of the internal structure of a Tapestry
application; end developers who refer to "page" are really referring to the
root
component
of the actual page.
Starting in release 5.2, the nature of pages changed considerably. Pages are no longer pooled instances. Instead,
pages are shared instances (per locale) but all internal mutable state is stored inside
PerthreadManager
. Page construction time is considered to extend past the
page loaded callback. This is not quite perfect from a
threading point-of-view (arguably, even write-once-read-many fields should be protected by synchronized blocks or
other mechanisms). At best, we can be assured that the entire page construction phase is protected by a single
synchronized block (but not on the page itself). An ideal system would build the page bottom to top so that all
assignments could take place in constructors, assigning to final fields. Maybe some day.
The Page object is never visible to end-user code, though it exposes an interface (PageLifecycleCallbackHub
that
is).-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final class
Page construction statistics for the page. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLifecycleListener
(PageLifecycleListener listener) Deprecated.void
addResetListener
(PageResetListener listener) Deprecated.in 5.3.4,void
attached()
Invoked to inform the page that it is attached to the current request.boolean
detached()
Invoked to inform the page that it is being detached from the current request.void
Discards all persistent field changes for the page containing the component.int
Returns the number of times the page has been attached to a request.getComponentElementByNestedId
(String nestedId) Retrieves a component element by its nested id (a sequence of simple ids, separated by dots).getFieldChange
(String nestedId, String fieldName) Gets a change for a field within the component.org.slf4j.Logger
Returns the logger of the root component element.getName()
Returns the short, logical name for the page.The root component of the page.The root component of the page.The selector (which includes Locale) used when the page was constructor.getStats()
Returns the page construction statistics for this page.boolean
Returns true if there are anyPageResetListener
listeners.boolean
Returns true if extract parameter count matching is enabled.void
loaded()
Inform the page that it is now completely loaded.void
Invoked to notifyPageResetListener
listeners.void
persistFieldChange
(ComponentResources resources, String fieldName, Object newValue) Posts a change to a persistent field.void
removeLifecycleListener
(PageLifecycleListener listener) Deprecated.in 5.3.4, due to introduction ofPageLifecycleCallbackHub.addPageLoadedCallback(Runnable)
void
setRootElement
(ComponentPageElement component) Invoked during page construction time to connect the page's root component to the page instance.void
setStats
(Page.Stats stats) Invoked once at the end of page construction, to provide page construction statistics.Methods inherited from interface org.apache.tapestry5.runtime.PageLifecycleCallbackHub
addPageAttachedCallback, addPageDetachedCallback, addPageLoadedCallback, addResetCallback, addVerifyCallback
-
Method Details
-
getName
Returns the short, logical name for the page. This is the page name as it might included in an action or page render URL (though it will be converted to lower case when it is included). -
getSelector
The selector (which includes Locale) used when the page was constructor. -
setRootElement
Invoked during page construction time to connect the page's root component to the page instance. -
getRootElement
The root component of the page. This is the wrapper around the end developer's view of the page. -
getRootComponent
The root component of the page. A convenience over invoking getRootElement().getComponent(). -
detached
boolean detached()Invoked to inform the page that it is being detached from the current request. This occurs just before the page is returned to the page pool. A page may be clean or dirty. A page is dirty if its dirty count is greater than zero (meaning that, during the render of the page, some components did not fully render), or if any of its listeners throw an exception from containingPageDidDetach(). The page pool should discard pages that are dirty, rather than store them into the pool. Under Tapestry 5.2 and pool-less pages, the result is ignored; all mutable state is expected to be discarded automatically from thePerthreadManager
. A future release of Tapestry will likely convert this method to type void.- Returns:
- true if the page is "dirty", false otherwise
- See Also:
-
attached
void attached()Invoked to inform the page that it is attached to the current request. This occurs when a page is first referenced within a request. If the page was created from scratch for this request, the call toloaded()
will preceded the call toattached()
. First all listeners havePageLifecycleListener.restoreStateBeforePageAttach()
invoked, followed byPageLifecycleListener.containingPageDidAttach()
. -
loaded
void loaded()Inform the page that it is now completely loaded. -
addLifecycleListener
Deprecated.Adds a listener that is notified of large scale page events. -
removeLifecycleListener
Deprecated.in 5.3.4, due to introduction ofPageLifecycleCallbackHub.addPageLoadedCallback(Runnable)
Removes a listener that was previously added.- Since:
- 5.2.0
-
getLogger
org.slf4j.Logger getLogger()Returns the logger of the root component element. Any logging about page construction or activity should be sent to this logger. -
getComponentElementByNestedId
Retrieves a component element by its nested id (a sequence of simple ids, separated by dots). The individual names in the nested id are matched without regards to case. A nested id of '' (the empty string) returns the root element of the page.- Throws:
UnknownValueException
- if the nestedId does not correspond to a component
-
persistFieldChange
Posts a change to a persistent field.- Parameters:
resources
- the component resources for the component or mixin containing the field whose value changedfieldName
- the name of the fieldnewValue
- the new value for the field
-
getFieldChange
Gets a change for a field within the component.- Parameters:
nestedId
- the nested component id of the component containing the fieldfieldName
- the name of the persistent field- Returns:
- the value, or null if no value is stored
-
discardPersistentFieldChanges
Discards all persistent field changes for the page containing the component. Changes are eliminated from persistent storage (such as theSession
) which will take effect in the next request (the attached page instance is not affected). -
addResetListener
Deprecated.in 5.3.4,Adds a new listener for page reset events.- Parameters:
listener
- will receive notifications when the page is accessed from a different page- Since:
- 5.2.0
-
hasResetListeners
boolean hasResetListeners()Returns true if there are anyPageResetListener
listeners.- Since:
- 5.2.0
-
pageReset
void pageReset()Invoked to notifyPageResetListener
listeners. -
setStats
Invoked once at the end of page construction, to provide page construction statistics.- Since:
- 5.3
-
getStats
Returns the page construction statistics for this page. -
getAttachCount
int getAttachCount()Returns the number of times the page has been attached to a request. This is a rough measure of how important the page is, relative to other pages. This value is volatile, changing constantly.- Since:
- 5.3
-
isExactParameterCountMatch
Returns true if extract parameter count matching is enabled.- Since:
- 5.4
- See Also:
-
PageLifecycleCallbackHub.addPageLoadedCallback(Runnable)
,PageLifecycleCallbackHub.addPageAttachedCallback(Runnable)
, orPageLifecycleCallbackHub.addPageDetachedCallback(Runnable)
instead