public abstract class AbstractComponent extends org.apache.hivemind.impl.BaseLocatable implements IComponent
IComponentinterface.| Constructor and Description |
|---|
AbstractComponent() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAsset(java.lang.String name,
IAsset asset)
Adds an asset to the component.
|
void |
addBody(IRender element)
Adds an element (which may be static text or a component) as a body element of this
component.
|
void |
addComponent(IComponent component)
Adds a component to a container.
|
protected void |
checkActiveLock() |
protected void |
cleanupAfterRender(IRequestCycle cycle)
Invoked by
render(IMarkupWriter, IRequestCycle)after the component renders. |
void |
enterActiveState()
Invoked after
IComponent.finishLoad(IRequestCycle, IPageLoader, IComponentSpecification)to
switch the component from its initial construction state into its active state. |
protected void |
finishLoad()
Invoked, as a convienience, from
finishLoad(IRequestCycle, IPageLoader, IComponentSpecification). |
void |
finishLoad(IRequestCycle cycle,
IPageLoader loader,
IComponentSpecification specification)
Invokes
finishLoad(). |
java.lang.String |
format(java.lang.String key,
java.lang.Object argument)
Deprecated.
To be removed in 4.1. Use
getMessages() instead. |
java.lang.String |
format(java.lang.String key,
java.lang.Object[] arguments)
Deprecated.
To be removed in 4.1. Use
getMessages() instead. |
java.lang.String |
format(java.lang.String key,
java.lang.Object argument1,
java.lang.Object argument2)
Deprecated.
To be removed in 4.1. Use
getMessages() instead. |
java.lang.String |
format(java.lang.String key,
java.lang.Object argument1,
java.lang.Object argument2,
java.lang.Object argument3)
Deprecated.
To be removed in 4.1. Use
getMessages() instead. |
IAsset |
getAsset(java.lang.String name)
Returns the named asset, or null if not found.
|
java.util.Map |
getAssets()
Returns the asset map for the component, which may be empty but will not be null.
|
IBeanProvider |
getBeans()
Returns the
IBeanProviderfor this component. |
IBinding |
getBinding(java.lang.String name)
Returns the named binding, or null if it doesn't exist.
|
java.util.Collection |
getBindingNames()
Returns a
Collectionof the names of all bindings (which includes bindings for both
formal and informal parameters). |
java.util.Map |
getBindings()
Returns an unmodifiable
Mapof all bindings for this component. |
IRender[] |
getBody()
Returns the body of the component, the element (which may be static HTML or components) that
the component immediately wraps.
|
int |
getBodyCount()
Returns the active number of elements in the the body, which may be zero.
|
IComponent |
getComponent(java.lang.String id)
Retrieves an contained component by its id.
|
java.util.Map |
getComponents()
Returns an unmodifiable
Mapof components, keyed on component id. |
IContainedComponent |
getContainedComponent()
Returns the
IContainedComponent. |
IComponent |
getContainer()
Returns the component which embeds the receiver.
|
java.lang.String |
getExtendedId()
Returns the name of the page, a slash, and this component's id path.
|
java.lang.String |
getId()
Returns the simple id of the component, as defined in its specification.
|
java.lang.String |
getIdPath()
Returns the qualified id of the component.
|
ListenerMap |
getListeners()
Returns a
ListenerMap for the component. |
java.lang.String |
getMessage(java.lang.String key)
Deprecated.
To be removed in 4.1. Use
getMessages() instead. |
org.apache.hivemind.Messages |
getMessages()
Returns component strings for the component.
|
INamespace |
getNamespace()
Returns the
INamespacein which the component was defined (as an alias). |
IPage |
getPage()
Returns the page which ultimately contains the receiver.
|
java.lang.Object |
getProperty(java.lang.String propertyName)
Deprecated.
|
IComponentSpecification |
getSpecification()
Returns the specification which defines the component.
|
protected boolean |
isInActiveState()
Returns true if the component has been transitioned into its active state by invoking
enterActiveState() |
boolean |
isParameterBound(java.lang.String parameterName)
Returns true if the specified parameter is bound.
|
boolean |
isRendering()
Returns true if the component is currently rendering.
|
void |
pageEndRender(PageEvent event)
Empty implementation of
PageEndRenderListener.pageEndRender(PageEvent). |
protected void |
prepareForRender(IRequestCycle cycle)
Invoked by
render(IMarkupWriter, IRequestCycle)to prepare the component to render. |
void |
render(IMarkupWriter writer,
IRequestCycle cycle)
The main method used to render the component.
|
void |
renderBody(IMarkupWriter writer,
IRequestCycle cycle)
Renders all elements wrapped by the receiver.
|
protected abstract void |
renderComponent(IMarkupWriter writer,
IRequestCycle cycle)
Invoked by
render(IMarkupWriter, IRequestCycle)to actually render the component
(with any parameter values already set). |
protected void |
renderInformalParameters(IMarkupWriter writer,
IRequestCycle cycle)
Converts informal parameters into additional attributes on the curently open tag.
|
void |
setBinding(java.lang.String name,
IBinding binding)
Adds the binding with the given name, replacing any existing binding with that name.
|
void |
setContainedComponent(IContainedComponent containedComponent)
Sets the
IComponent.getContainedComponent() property; this may only be done once. |
void |
setContainer(IComponent value)
Sets the container of the component.
|
void |
setId(java.lang.String value)
Sets the id of the component.
|
void |
setNamespace(INamespace namespace)
Sets the
INamespacefor the component. |
void |
setPage(IPage value)
Sets the page which ultimiately contains the component.
|
void |
setProperty(java.lang.String propertyName,
java.lang.Object value)
Deprecated.
|
java.lang.String |
toString() |
public AbstractComponent()
public void addAsset(java.lang.String name, IAsset asset)
IComponentaddAsset in interface IComponentpublic void addComponent(IComponent component)
IComponentaddComponent in interface IComponentIPageLoaderpublic void addBody(IRender element)
renderBody(IMarkupWriter, IRequestCycle).addBody in interface IComponentpublic void finishLoad(IRequestCycle cycle, IPageLoader loader, IComponentSpecification specification)
finishLoad(). Subclasses may overide as needed, but must invoke this
implementation. BaseComponent loads its HTML template.finishLoad in interface IComponentprotected void renderInformalParameters(IMarkupWriter writer, IRequestCycle cycle)
Invoked from subclasses to allow additional attributes to be specified within a tag (this
works best when there is a one-to-one corespondence between an IComponentand a HTML
element.
Iterates through the bindings for this component. Filters out bindings for formal parameters.
For each acceptible key, the value is extracted using IBinding.getObject(). If the
value is null, no attribute is written.
If the value is an instance of IAsset, then IAsset.buildURL()
is invoked to convert the asset to a URL.
Finally, IMarkupWriter.attribute(String,String)is invoked with the value (or the
URL).
The most common use for informal parameters is to support the HTML class attribute (for use with cascading style sheets) and to specify JavaScript event handlers.
Components are only required to generate attributes on the result phase; this can be skipped during the rewind phase.
public IBinding getBinding(java.lang.String name)
In Tapestry 3.0, it was possible to force a binding to be stored in a component property by
defining a concrete or abstract property named "nameBinding" of type IBinding. This
has been removed in release 4.0 and bindings are always stored inside a Map of the component.
getBinding in interface IComponentsetBinding(String,IBinding)public boolean isParameterBound(java.lang.String parameterName)
public IComponent getComponent(java.lang.String id)
IComponentgetComponent in interface IComponentpublic IComponent getContainer()
IComponentA page returns null.
getContainer in interface IComponentpublic void setContainer(IComponent value)
IComponentApplicationRuntimeException.setContainer in interface IComponentpublic java.lang.String getExtendedId()
getExtendedId in interface IComponentgetIdPath()public java.lang.String getId()
IComponentAn id will be unique within the component which contains this component.
A pagewill always return null.
getId in interface IComponentpublic void setId(java.lang.String value)
IComponentApplicationRuntimeException.setId in interface IComponentpublic java.lang.String getIdPath()
IComponentpage
to this component, showing how components contain each other.
A pagewill always return null. A component contained on a page returns its
simple id. Other components return their container's id path followed by a period and their
own name.
getIdPath in interface IComponentIComponent.getId()public IPage getPage()
IComponentgetPage in interface IComponentpublic void setPage(IPage value)
IComponentApplicationRuntimeException.setPage in interface IComponentpublic void renderBody(IMarkupWriter writer, IRequestCycle cycle)
renderBody in interface IComponentpublic void setBinding(java.lang.String name, IBinding binding)
setBinding in interface IComponentgetBinding(String)public java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Map getComponents()
Mapof components, keyed on component id. Never returns null,
but may return an empty map. The returned map is immutable.getComponents in interface IComponentpublic java.util.Map getAssets()
IComponentThe return value is unmodifiable.
getAssets in interface IComponentpublic IAsset getAsset(java.lang.String name)
IComponentgetAsset in interface IComponentpublic java.util.Collection getBindingNames()
IComponentCollectionof the names of all bindings (which includes bindings for both
formal and informal parameters).
The return value is unmodifiable. It will be null for a page, or may simply be
empty for a component with no bindings.
getBindingNames in interface IComponentpublic java.util.Map getBindings()
Mapof all bindings for this component.getBindings in interface IComponentpublic ListenerMap getListeners()
ListenerMap for the component. A ListenerMap contains a number of
synthetic read-only properties that implement the IActionListenerinterface, but in
fact, cause public instance methods to be invoked.getListeners in interface IComponentpublic IBeanProvider getBeans()
IBeanProviderfor this component. This is lazily created the first time
it is needed.getBeans in interface IComponentprotected void finishLoad()
finishLoad(IRequestCycle, IPageLoader, IComponentSpecification). This implemenation
does nothing. Subclasses may override without invoking this implementation.public final void render(IMarkupWriter writer, IRequestCycle cycle)
prepareForRender(IRequestCycle), then
renderComponent(IMarkupWriter, IRequestCycle).
cleanupAfterRender(IRequestCycle)is invoked in a finally block.
Subclasses should not override this method; instead they will implement
renderComponent(IMarkupWriter, IRequestCycle).
protected void prepareForRender(IRequestCycle cycle)
render(IMarkupWriter, IRequestCycle)to prepare the component to render.
This implementation sets JavaBeans properties from matching bound parameters. This
implementation does nothing.protected abstract void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
render(IMarkupWriter, IRequestCycle)to actually render the component
(with any parameter values already set). This is the method that subclasses must implement.protected void cleanupAfterRender(IRequestCycle cycle)
render(IMarkupWriter, IRequestCycle)after the component renders. This
implementation does nothing.public INamespace getNamespace()
IComponentINamespacein which the component was defined (as an alias).getNamespace in interface IComponentpublic void setNamespace(INamespace namespace)
IComponentINamespacefor the component. The namespace should only be set once.setNamespace in interface IComponentpublic IRender[] getBody()
getBodyCount()public int getBodyCount()
getBody()public void pageEndRender(PageEvent event)
PageEndRenderListener.pageEndRender(PageEvent). This allows
classes to implement PageRenderListenerand only implement
the PageBeginRenderListener.pageBeginRender(PageEvent)method.public void setProperty(java.lang.String propertyName, java.lang.Object value)
setProperty in interface IComponentpropertyName - the property namevalue - the provided valueIComponentpublic java.lang.Object getProperty(java.lang.String propertyName)
getProperty in interface IComponentpropertyName - the property nameIComponentpublic final boolean isRendering()
IComponentisRendering in interface IComponentprotected final boolean isInActiveState()
enterActiveState()public final void enterActiveState()
IComponentIComponent.finishLoad(IRequestCycle, IPageLoader, IComponentSpecification)to
switch the component from its initial construction state into its active state. The
difference concerns parameters, whose defaults values may be set from inside
IComponent.finishLoad(IRequestCycle, IPageLoader, IComponentSpecification).enterActiveState in interface IComponentprotected final void checkActiveLock()
public org.apache.hivemind.Messages getMessages()
IComponentgetMessages in interface IComponentpublic IComponentSpecification getSpecification()
IComponentgetSpecification in interface IComponentpublic java.lang.String getMessage(java.lang.String key)
getMessages() instead.getMessage in interface IComponentkey - the key used to locate the messagepublic java.lang.String format(java.lang.String key, java.lang.Object[] arguments)
getMessages() instead.Messages.format(java.lang.String, java.lang.Object[]).key - the key used to obtain a localized patternarguments - passed to the formatterpublic java.lang.String format(java.lang.String key, java.lang.Object argument)
getMessages() instead.IMessages#format(String, Locale, Object)public java.lang.String format(java.lang.String key, java.lang.Object argument1, java.lang.Object argument2)
getMessages() instead.Messages.format(String, Object, Object).public java.lang.String format(java.lang.String key, java.lang.Object argument1, java.lang.Object argument2, java.lang.Object argument3)
getMessages() instead.Messages.format(String, Object, Object, Object).public final IContainedComponent getContainedComponent()
IComponentIContainedComponent. This will be null for
pages. This property is set when a component is constructed, and links the component instance
to the reference in the containing page or component's template or specification. This is
useful to allow a component to know its type or the meta-data associated with the component.getContainedComponent in interface IComponentpublic final void setContainedComponent(IContainedComponent containedComponent)
IComponentIComponent.getContainedComponent() property; this may only be done once.setContainedComponent in interface IComponentcontainedComponent - may not be null