public class ComponentPageElementImpl extends BaseLocatable implements ComponentPageElement
RenderCommand and represents a component within an overall page. Much of a
component page
element's behavior is delegated to user code, via a Component instance.
Once instantiated, a ComponentPageElement should be registered as a
lifecycle listener. This could be done inside the constructors, but that tends to complicate unit tests, so its done
by PageElementFactoryImpl. There's still a bit of refactoring in this
class (and its many inner classes) that can improve overall efficiency.
Modified for Tapestry 5.2 to adjust for the no-pooling approach (shared instances with externalized mutable state).| Constructor and Description |
|---|
ComponentPageElementImpl(Page page,
Instantiator instantiator,
ComponentPageElementResources elementResources)
Constructor for the root component of a page.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBlock(String blockId,
Block block)
Used during the contruction of a page to add a non-anonymous Block to the component.
|
void |
addMixin(String mixinId,
Instantiator instantiator,
String... order)
Adds a mixin.
|
void |
addToBody(RenderCommand element)
Used during the construction of the page.
|
void |
addToTemplate(RenderCommand element)
Used during the construction of a page.
|
void |
bindMixinParameter(String mixinId,
String parameterName,
Binding binding) |
void |
bindParameter(String parameterName,
Binding binding)
Used during construction of the page to identify the binding for a particular parameter.
|
Link |
createEventLink(String eventType,
Object... context)
Creates a component event request link as a callback for this component.
|
Link |
createFormEventLink(String eventType,
Object... context)
Creates a component event request link as a callback for this component.
|
protected RenderPhaseEvent |
createRenderEvent(RenderQueue queue) |
boolean |
dispatchEvent(ComponentEvent event)
Asks each mixin and component to
Component.dispatchComponentEvent(ComponentEvent), returning true if any
handler was found. |
void |
enqueueBeforeRenderBody(RenderQueue queue)
Invoked when the component should render its body.
|
Block |
findBlock(String id)
As with
ComponentResourcesCommon.getBlock(String), but returns null if the block is not found. |
Binding |
getBinding(String parameterName)
Returns the binding for the given parameter name, or null.
|
Block |
getBlock(String id)
Returns a block from the component's template, referenced by its id.
|
Block |
getBody()
Returns the body of this component as a (possibly empty) block.
|
String |
getCompleteId()
Returns a string consisting of the logical name of the containing page, and the
nested id
of this component, separated by a colon. |
Component |
getComponent()
Returns the core component associated with this page element (as opposed to any mixins attached to the
component).
|
InternalComponentResources |
getComponentResources()
Returns the resources associated with the core component.
|
ComponentPageElement |
getContainerElement()
Containing component (or null for the root component of a page).
|
Page |
getContainingPage()
Returns the page which contains this component.
|
String |
getElementName(String defaultElementName)
Returns the name of element that represents the component in its template, or the provided default element name
if the element was a component type (in the Tapestry namespace).
|
ComponentPageElement |
getEmbeddedElement(String embeddedId)
Retrieves a component page element by its id.
|
org.slf4j.Logger |
getEventLogger()
Returns a logger used to for logging event dispatch and event method invocation.
|
String |
getId()
Returns the simple (or local) id of the component.
|
Map<String,Binding> |
getInformalParameterBindings()
Constructs a map linking informal parameters to the corresponding bindings.
|
Locale |
getLocale()
Returns the locale for the page containing this component.
|
org.slf4j.Logger |
getLogger()
Returns the log instance associated with the component (which is based on the component or mixin's class name).
|
Component |
getMixinByClassName(String mixinClassName)
Returns the mixin instance for the fully qualfied mixin class name.
|
ComponentResources |
getMixinResources(String mixinId)
Returns the
ComponentResources for a mixin attached to this component element. |
String |
getNestedId()
Return a string consisting the concatenated ids of all containing components, separated by periods.
|
String |
getPageName()
Returns the logical name of the page containing this component.
|
ComponentResourceSelector |
getResourceSelector()
Returns the selector used when constructing the component and its containing page.
|
boolean |
hasBody()
Returns true if the element has a body and false otherwise.
|
boolean |
isLoaded()
Returns true if the component has finished loading.
|
boolean |
isRendering()
Returns true if the component is currently rendering, false otherwise.
|
ComponentPageElement |
newChild(String id,
String nestedId,
String completeId,
String elementName,
Instantiator instantiator,
Location location)
Creates a new child component of the invoked component.
|
void |
render(MarkupWriter writer,
RenderQueue queue)
Pushes the SetupRender phase state onto the queue.
|
String |
toString() |
boolean |
triggerContextEvent(String eventType,
EventContext context,
ComponentEventCallback callback)
Triggers a component event.
|
boolean |
triggerEvent(String eventType,
Object[] contextValues,
ComponentEventCallback callback)
A convenience method for invoking
ComponentResourcesCommon.triggerContextEvent(String, EventContext , ComponentEventCallback). |
getLocationclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetLocationpublic ComponentPageElementImpl(Page page, Instantiator instantiator, ComponentPageElementResources elementResources)
public ComponentPageElement newChild(String id, String nestedId, String completeId, String elementName, Instantiator instantiator, Location location)
ComponentPageElementnewChild in interface ComponentPageElementid - simple id of the new componentelementName - name of the component's element in its container's templateinstantiator - used to create a component instance, and access the component's modellocation - location of the element within its container's template @return the new componentpublic void addMixin(String mixinId, Instantiator instantiator, String... order)
ComponentPageElementaddMixin in interface ComponentPageElementmixinId - a unique id for the mixin, the last term of the mixin's class nameinstantiator - used to instantiate an instance of the mixinorder - Ordering strings used to determine the order of mixin execution.public void bindMixinParameter(String mixinId, String parameterName, Binding binding)
bindMixinParameter in interface ComponentPageElementmixinId - id of previously added mixinparameterName - simple (unqualified) name of parameterbinding - binding for parameterpublic Binding getBinding(String parameterName)
InternalComponentResourcesCommongetBinding in interface InternalComponentResourcesCommonparameterName - name of component parameterpublic void bindParameter(String parameterName, Binding binding)
InternalComponentResourcesCommonbindParameter in interface InternalComponentResourcesCommonpublic void addToBody(RenderCommand element)
BodyPageElementaddToBody in interface BodyPageElementpublic void addToTemplate(RenderCommand element)
ComponentPageElementaddToTemplate in interface ComponentPageElementpublic void enqueueBeforeRenderBody(RenderQueue queue)
ComponentPageElementenqueueBeforeRenderBody in interface ComponentPageElementpublic String getCompleteId()
ComponentResourcesCommonnested id
of this component, separated by a colon. I.e., "MyPage:foo.bar.baz". For a page, returns just the page's name.
This value is often used to obtain an equivalent component instance in a later request.getCompleteId in interface ComponentResourcesCommonComponentSource.getComponent(String)public Component getComponent()
ComponentPageElementgetComponent in interface ComponentPageElementpublic InternalComponentResources getComponentResources()
ComponentPageElementgetComponentResources in interface ComponentPageElementpublic ComponentPageElement getContainerElement()
ComponentPageElementgetContainerElement in interface ComponentPageElementpublic Page getContainingPage()
ComponentPageElementgetContainingPage in interface ComponentPageElementpublic ComponentPageElement getEmbeddedElement(String embeddedId)
ComponentPageElementgetEmbeddedElement in interface ComponentPageElementembeddedId - used to locate the elementpublic String getId()
ComponentResourcesCommongetId in interface ComponentResourcesCommonpublic org.slf4j.Logger getLogger()
ComponentResourcesCommongetLogger in interface ComponentResourcesCommonComponentModel.getLogger()public Component getMixinByClassName(String mixinClassName)
InternalComponentResourcesCommongetMixinByClassName in interface InternalComponentResourcesCommonmixinClassName - fully qualified class namepublic ComponentResources getMixinResources(String mixinId)
ComponentPageElementComponentResources for a mixin attached to this component element. Mixin
ids are the simple names of the mixin class.getMixinResources in interface ComponentPageElementmixinId - the mixin id (case insensitive)public String getNestedId()
ComponentResourcesCommongetNestedId in interface ComponentResourcesCommonpublic boolean dispatchEvent(ComponentEvent event)
ComponentPageElementComponent.dispatchComponentEvent(ComponentEvent), returning true if any
handler was found.dispatchEvent in interface ComponentPageElementevent - to be handledpublic boolean isLoaded()
InternalComponentResourcesCommonisLoaded in interface InternalComponentResourcesCommonPageLifecycleListener.containingPageDidLoad()public boolean isRendering()
ComponentResourcesCommonisRendering in interface ComponentResourcesCommonpublic final void render(MarkupWriter writer, RenderQueue queue)
render in interface RenderCommandpublic boolean triggerEvent(String eventType, Object[] contextValues, ComponentEventCallback callback)
ComponentResourcesCommonComponentResourcesCommon.triggerContextEvent(String, EventContext , ComponentEventCallback). Wraps
the context values into an EventContext.triggerEvent in interface ComponentResourcesCommoneventType - event type (as determined from the request, or otherwise by design)contextValues - Values that may be provided to the event handler method as method parameters, or null if no
context values are availablecallback - the handler to be informed of the result, or null if the event is a notification that does
not support return values from event handler methods (the value true is allowed even if the
handler is null).OnEventWorker,
OnEventpublic boolean triggerContextEvent(String eventType, EventContext context, ComponentEventCallback callback)
ComponentResourcesCommontriggerContextEvent in interface ComponentResourcesCommoneventType - event type (as determined from the request, or otherwise by design)context - the context (as extracted from the request, or provided by the triggering component); these
values may be provided to event handler methods via their parameters (may not be null)callback - the handler to be informed of the result, or null if the event is a notification that does not
support return values from event handler methods (the value true is allowed even if the handler
is null).OnEventWorker,
OnEventpublic Locale getLocale()
ComponentResourcesCommongetLocale in interface ComponentResourcesCommonComponentResourcesCommon.getResourceSelector()public String getElementName(String defaultElementName)
ComponentResourcesCommongetElementName in interface ComponentResourcesCommondefaultElementName - element name to return if the element name is not known (may be null)public Block getBlock(String id)
ComponentResourcesCommongetBlock in interface ComponentResourcesCommonid - the id of the block (case insensitive)ComponentResourcesCommon.findBlock(String)public Block findBlock(String id)
ComponentResourcesCommonComponentResourcesCommon.getBlock(String), but returns null if the block is not found.findBlock in interface ComponentResourcesCommonid - the id of the block (case insensitive)public void addBlock(String blockId, Block block)
ComponentPageElementaddBlock in interface ComponentPageElementComponentResourcesCommon.getBlock(String)public String getPageName()
ComponentResourcesCommongetPageName in interface ComponentResourcesCommonpublic boolean hasBody()
ComponentResourcesCommonhasBody in interface ComponentResourcesCommonpublic Block getBody()
ComponentResourcesCommongetBody in interface ComponentResourcesCommonpublic Map<String,Binding> getInformalParameterBindings()
InternalComponentResourcesCommongetInformalParameterBindings in interface InternalComponentResourcesCommonpublic org.slf4j.Logger getEventLogger()
ComponentPageElementgetEventLogger in interface ComponentPageElementpublic Link createEventLink(String eventType, Object... context)
ComponentResourcesCommoncreateEventLink in interface ComponentResourcesCommoneventType - the type of event to be triggered. Event types should be Java identifiers (contain only
letters, numbers and the underscore).context - additional objects to be encoded into the path portion of the link; each is converted to a
string and URI encodedpublic Link createFormEventLink(String eventType, Object... context)
ComponentResourcesCommoncreateFormEventLink in interface ComponentResourcesCommoneventType - the type of event to be triggered. Event types should be Java identifiers (contain only
letters, numbers and the underscore).context - additional objects to be encoded into the path portion of the link; each is converted to a
string and URI encodedprotected RenderPhaseEvent createRenderEvent(RenderQueue queue)
public ComponentResourceSelector getResourceSelector()
ComponentResourcesCommongetResourceSelector in interface ComponentResourcesCommon5.6.4 - Copyright © 2003-2021 The Apache Software Foundation.