Class Component
- java.lang.Object
-
- org.apache.wicket.Component
-
- All Implemented Interfaces:
Serializable
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IMetadataContext<Serializable,Component>
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
MarkupContainer
,WebComponent
public abstract class Component extends Object implements IClusterable, IConverterLocator, IRequestableComponent, IHeaderContributor, IHierarchical<Component>, IEventSink, IEventSource, IMetadataContext<Serializable,Component>, IFeedbackContributor
Component serves as the highest level abstract base class for all components.- Identity - All Components must have a non-null id which is retrieved by calling
getId(). The id must be unique within the
MarkupContainer
that holds the Component, but does not have to be globally unique or unique within a Page's component hierarchy. - Hierarchy - A component has a parent which can be retrieved with
getParent()
. If a component is an instance of MarkupContainer, it may have children. In this way it has a place in the hierarchy of components contained on a given page.The path from the Page at the root of the component hierarchy to a given Component is simply the concatenation with colon separators of each id along the way. For example, the path "a:b:c" would refer to the component named "c" inside the MarkupContainer named "b" inside the container named "a". The path to a component can be retrieved by calling
getPath()
. To get a Component path relative to the page that contains it, you can callgetPageRelativePath()
. - LifeCycle - Components participate in the following lifecycle phases:
- Construction - A Component is constructed with the Java language new operator.
Children may be added during construction if the Component is a MarkupContainer.
IComponentInstantiationListener
s are notified of component instantiation.onInitialize()
is called on the component as soon as the component is part of a page's component tree. At this state the component is able to access its markup. - Request Handling - An incoming request is processed by a protocol request handler such
as
WicketFilter
. An associated Application object createsSession
,Request
andResponse
objects for use by a given Component in updating its model and rendering a response. These objects are stored inside a container calledRequestCycle
which is accessible viagetRequestCycle()
. The convenience methodsgetRequest()
,getResponse()
andgetSession()
provide easy access to the contents of this container. - Listener Invocation - If the request references an
IRequestListener
on an existing Component (or one of itsBehavior
s, see below), that listener is notified, allowing arbitrary user code to handle events such as link clicks or form submits. Although arbitrary listeners are supported in Wicket, the need to implement a new class of listener is unlikely for a web application and even the need to implement a listener interface directly is highly discouraged. Instead, calls to listeners are routed through logic specific to the event, resulting in calls to user code through other overridable methods. SeeForm
for an example of a component which listens for events viaIRequestListener
. - Rendering - Before a page or part of a page (in case of Ajax updates) is rendered, all
containing components are able to prepare for rendering via two hook methods:
onConfigure()
(regardless whether they are visible or not) andonBeforeRender()
(if visible only) .
A markup response is generated by the Component viarender()
, which calls subclass implementation code contained inonRender()
. Once this phase begins, a Component becomes immutable. Attempts to alter the Component will result in a WicketRuntimeException. - Detachment - Each request cycle finishes by detaching all touched components.
Subclasses should clean up their state by overriding
onDetach()
or more specificallydetachModels()
if they keep references to models beside the default model.
- Construction - A Component is constructed with the Java language new operator.
Children may be added during construction if the Component is a MarkupContainer.
- Visibility - If a component is not visible (see
setVisible(boolean)
) it will not render a response (nor will their children). - Enabling - Component subclasses take into account their enabled state (see
setEnabled(boolean)
when rendering, and in case of aFormComponent
will not not update its model while the request is handled. - Models - The primary responsibility of a component is to use its model (an object that
implements
IModel
) to render a response in an appropriate markup language, such as HTML. In addition,FormComponent
s know how to update their models based on request information, seeFormComponent.updateModel()
. Since the IModel interface is a wrapper around another object, a convenience methodgetDefaultModelObject()
is provided to retrieve the object from its IModel wrapper. A further convenience method,getDefaultModelObjectAsString()
, is provided for the very common operation of converting the wrapped object to a String.
The component's model can be passed in the constructor or set viasetDefaultModel(IModel)
. In neither case a model can be created on demand withinitModel()
.
Note that a component can have more models besides its default model. - Behaviors - You can add multiple
Behavior
s to any component if you need to dynamically alter the behavior of components, e.g. manipulate attributes of the markup tag to which a Component is attached. Behaviors take part in the component's lifecycle through various callback methods. - Locale - The Locale for a Component is available through
getLocale()
, which delegates to its parent's locale, finally consulting theSession
's locale. - Style - The Session's style ("skin") is available through
getStyle()
. Styles are intended to give a particular look to all components or resources in a session that is independent of its Locale. For example, a style might be a set of resources, including images and markup files, which gives the design look of "ocean" to the user. If the Session's style is set to "ocean" and these resources are given names suffixed with "_ocean", Wicket's resource management logic will prefer these resources to other resources, such as default resources, which are not as good of a match. - Variation - Whereas styles are Session (user) specific, variations are component
specific. E.g. if the Style is "ocean" and
getVariation()
returnss "NorthSea", than the resources are given the names suffixed with "_ocean_NorthSea". - String Resources - Components can have associated String resources via the
Application's Localizer, which is available through the method
getLocalizer()
. The convenience methodsgetString(String key)
andgetString(String key, IModel model)
wrap the identical methods on the Application Localizer for easy access in Components. - Feedback Messages - The
debug(Serializable)
,info(Serializable)
,warn(Serializable)
,error(java.io.Serializable)
andfatal(Serializable)
methods associate feedback messages with a Component. It is generally not necessary to use these methods directly since Wicket validators automatically register feedback messages on Components. Feedback message for a given Component can be retrieved withgetFeedbackMessages()
. - Versioning - Pages are the unit of versioning in Wicket, but fine-grained control of
which Components should participate in versioning is possible via the
setVersioned(boolean)
method. The versioning participation of a given Component can be retrieved withisVersioned()
. - Page - The Page containing any given Component can be retrieved by calling
getPage()
. If the Component is not attached to a Page, an IllegalStateException will be thrown. An equivalent method,findPage()
is available for special circumstances where it might be desirable to get a null reference back instead. - Application - The
getApplication()
method provides convenient access to theApplication
for a Component. - AJAX support- Components can be re-rendered after the whole Page has been rendered at least once by calling doRender().
- Security - All components are subject to an
IAuthorizationStrategy
which controls instantiation, visibility and enabling. SeeSimplePageAuthorizationStrategy
for a simple implementation.
- Author:
- Jonathan Locke, Chris Turner, Eelco Hillenius, Johan Compagner, Juergen Donnerstag, Igor Vaynberg (ivaynberg)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Action
ENABLE
Action used with IAuthorizationStrategy to determine whether a component is allowed to be enabled.protected static int
FLAG_INITIALIZED
onInitialize calledprotected static int
FLAG_RESERVED1
Reserved subclass-definable flag bitprotected static int
FLAG_RESERVED2
Reserved subclass-definable flag bitprotected static int
FLAG_RESERVED3
Reserved subclass-definable flag bitprotected static int
FLAG_RESERVED4
Reserved subclass-definable flag bitprotected static int
FLAG_RESERVED5
Reserved subclass-definable flag bitprotected static int
FLAG_RESERVED8
Reserved subclass-definable flag bitstatic String
PARENT_PATH
Path segment that represents this component's parentstatic char
PATH_SEPARATOR
Separator for component pathsstatic Action
RENDER
Action used with IAuthorizationStrategy to determine whether a component and its children are allowed to be rendered.protected static short
RFLAG_CONTAINER_DEQUEING
protected static short
RFLAG_CONTAINER_HAS_REMOVALS
This flag tracks if removals have been set on this component.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Component
add(Behavior... behaviors)
Adds a behavior modifier to the component.protected void
addStateChange()
TODO WICKET-NG rename to something more useful - like componentChanged(), this method used to be called with a Change object Adds state change to page.void
beforeRender()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.boolean
canCallListener()
Checks whether or not anIRequestListener
can be invoked on this component.boolean
canCallListenerAfterExpiry()
protected void
checkComponentTag(ComponentTag tag, String name)
Checks whether the given type has the expected name.protected void
checkComponentTagAttribute(ComponentTag tag, String key, String... values)
Checks that a given tag has a required attribute value.protected void
checkHierarchyChange(Component component)
Checks whether the hierarchy may be changed at all, and throws an exception if this is not the case.void
clearOriginalDestination()
Clears any data about previously intercepted page.void
configure()
TriggersonConfigure()
to be invoked on this component if it has not already during this request.void
continueToOriginalDestination()
Redirects to any intercept page previously specified by a call toredirectToInterceptPage(Page)
.protected IConverter<?>
createConverter(Class<?> type)
Factory method for converters to be used by this component, returnsnull
by default.void
debug(Serializable message)
Registers a debug feedback message for this componentvoid
detach()
Detaches the component.protected void
detachModel()
Detaches the model for this component if it is detachable.void
detachModels()
Detaches all modelsboolean
determineVisibility()
Determines whether or not a component should be visible, taking into account all the factors:isVisible()
,isVisibilityAllowed()
,isRenderAllowed()
void
error(Serializable message)
Registers an error feedback message for this componentprotected String
exceptionMessage(String message)
Suffixes an exception message with useful information about this.void
fatal(Serializable message)
Registers a fatal feedback message for this componentprotected MarkupStream
findMarkupStream()
Finds the markup stream for this component.protected Page
findPage()
If this Component is a Page, returns self.<Z> Z
findParent(Class<Z> c)
Finds the first container parent of this component of the given class.MarkupContainer
findParentWithAssociatedMarkup()
Component
get(String path)
Gets the component at the given path.String
getAjaxRegionMarkupId()
Returns the id of the markup region that will be updated via ajax.Application
getApplication()
Gets interface to application that this component is a part of.Behavior
getBehaviorById(int id)
Gets the behavior for the specified idint
getBehaviorId(Behavior behavior)
Gets a stable id for the specified non-temporary behavior.List<? extends Behavior>
getBehaviors()
Gets the currently coupledBehavior
s as an unmodifiable list.<M extends Behavior>
List<M>getBehaviors(Class<M> type)
Gets the subset of the currently coupledBehavior
s that are of the provided type as an unmodifiable list.String
getClassRelativePath()
<C> IConverter<C>
getConverter(Class<C> type)
Get the converter that should be used by this component, delegates tocreateConverter(Class)
and then to the application'sIConverterLocator
.IModel<?>
getDefaultModel()
Gets the model.Object
getDefaultModelObject()
Gets the backing model object.String
getDefaultModelObjectAsString()
Gets a model object as a string.String
getDefaultModelObjectAsString(Object modelObject)
Gets a model object as a string.boolean
getEscapeModelStrings()
Gets whether model strings should be escaped.FeedbackMessages
getFeedbackMessages()
Gets feedback messages for this component.protected boolean
getFlag(int flag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.String
getId()
Gets the id of this component.IModel<?>
getInnermostModel()
protected IModel<?>
getInnermostModel(IModel<?> model)
Finds the innermost IModel object for an IModel that might contain nested IModel(s).Locale
getLocale()
Gets the locale for this component.Localizer
getLocalizer()
Convenience method to provide easy access to the localizer object within any component.IMarkupFragment
getMarkup()
Get the Markup associated with the Component.ValueMap
getMarkupAttributes()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.String
getMarkupId()
Retrieves id by which this component is represented within the markup.String
getMarkupId(boolean createIfDoesNotExist)
Retrieves id by which this component is represented within the markup.String
getMarkupIdFromMarkup()
Object
getMarkupIdImpl()
Get the markupIdprotected IMarkupSourcingStrategy
getMarkupSourcingStrategy()
Get the markup sourcing strategy for the component.protected ComponentTag
getMarkupTag()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.<M extends Serializable>
MgetMetaData(MetaDataKey<M> key)
Gets metadata for this component using the given key.IModelComparator
getModelComparator()
Gets the component's current model comparator.boolean
getOutputMarkupId()
Gets whether or not component will output id attribute into the markup.boolean
getOutputMarkupPlaceholderTag()
Gets whether or not an invisible component will render a placeholder tag.Page
getPage()
Gets the page holding this component.String
getPageRelativePath()
Gets the path to this component relative to its containing page, i.e.MarkupContainer
getParent()
Gets any parent container, or null if there is none.String
getPath()
Gets this component's path.boolean
getRenderBodyOnly()
If false the component's tag will be printed as well as its body (which is default).Request
getRequest()
RequestCycle
getRequestCycle()
Gets the active request cycle for this componentprotected boolean
getRequestFlag(short flag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.Response
getResponse()
Session
getSession()
Gets the current Session object.long
getSizeInBytes()
protected boolean
getStatelessHint()
Returns whether the component can be stateless.String
getString(String key)
String
getString(String key, IModel<?> model)
String
getString(String key, IModel<?> model, String defaultValue)
String
getStyle()
A convenience method to access the Sessions's style.String
getVariation()
Gets the variation string of this component that will be used to look up markup for this component.boolean
hasBeenRendered()
Gets whether this component was rendered at least once.boolean
hasErrorMessage()
boolean
hasFeedbackMessage()
void
info(Serializable message)
Registers an informational feedback message for this componentprotected IModel<?>
initModel()
Called when a null model is about to be retrieved in order to allow a subclass to provide an initial model.void
internalInitialize()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.protected void
internalOnModelChanged()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.protected void
internalRenderComponent()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.void
internalRenderHead(HtmlHeaderContainer container)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.boolean
isActionAuthorized(Action action)
Authorizes an action for a component.boolean
isAuto()
protected boolean
isBehaviorAccepted(Behavior behavior)
Components are allowed to reject behavior modifiers.boolean
isEnableAllowed()
boolean
isEnabled()
Gets whether this component is enabled.boolean
isEnabledInHierarchy()
Calculates enabled state of the component taking its hierarchy into account.protected boolean
isIgnoreAttributeModifier()
If true, all attribute modifiers will be ignoredboolean
isInitialized()
Checks if the component has been initialized -onInitialize()
has been calledboolean
isRenderAllowed()
Checks the security strategy if theRENDER
action is allowed on this componentboolean
isRendering()
Says if the component is rendering currently.boolean
isStateless()
Returns if the component is stateless or not.boolean
isVersioned()
boolean
isVisibilityAllowed()
Gets whether or not visibility is allowed on this component.boolean
isVisible()
Gets whether this component and any children are visible.boolean
isVisibleInHierarchy()
Checks if the component itself and all its parents are visible.void
markRendering(boolean setRenderingFlag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.void
modelChanged()
Called to indicate that the model content for this component has been changedvoid
modelChanging()
Called to indicate that the model content for this component is about to changeprotected IMarkupSourcingStrategy
newMarkupSourcingStrategy()
IfgetMarkupSourcingStrategy()
returns null, this method will be called.protected void
onAfterRender()
Called immediately after a component and all its children have been rendered, regardless of any exception.protected void
onBeforeRender()
Called on all visible components before any component is rendered.protected void
onComponentTag(ComponentTag tag)
Processes the component tag.void
onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
Processes the body.protected void
onConfigure()
Called on all components before any component is rendered.protected void
onDetach()
Called to allow a component to detach resources after use.void
onEvent(IEvent<?> event)
Called when an event is sent to this sinkprotected void
onInitialize()
This method is meant to be used as an alternative to initialize components.protected void
onModelChanged()
Called anytime a model is changed after the change has occurredprotected void
onModelChanging()
Called anytime a model is changed, but before the change actually occursprotected void
onReAdd()
This method is called whenever a component is re-added to the page's component tree, if it had been removed at some earlier time, i.e., if it is already initialized (seeisInitialized()
).protected void
onRemove()
Called to notify the component it is being removed from the component hierarchy Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.protected abstract void
onRender()
Implementation that renders this component.void
redirectToInterceptPage(Page page)
Redirects browser to an intermediate page such as a sign-in page.void
remove()
Removes this component from its parent.Component
remove(Behavior... behaviors)
Removes behavior from componentvoid
render()
Render this component and all its children.protected void
renderComponentTag(ComponentTag tag)
Writes a simple tag out to the response stream.void
rendered()
Called to indicate that a component has been rendered.void
renderHead(IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.void
renderPart()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.protected void
renderPlaceholderTag(ComponentTag tag, Response response)
Renders a placeholder tag for the component when it is invisible andsetOutputMarkupPlaceholderTag(boolean)
has been called withtrue
.protected void
replaceComponentTagBody(MarkupStream markupStream, ComponentTag tag, CharSequence body)
Replaces the body with the given one.Component
replaceWith(Component replacement)
Replaces this component with another.boolean
sameInnermostModel(Component component)
boolean
sameInnermostModel(IModel<?> model)
<T> void
send(IEventSink sink, Broadcast type, T payload)
Sends an eventprotected Component
setAuto(boolean auto)
Component
setDefaultModel(IModel<?> model)
Sets the given model.Component
setDefaultModelObject(Object object)
Sets the backing model object.Component
setEnabled(boolean enabled)
Sets whether this component is enabled.Component
setEscapeModelStrings(boolean escapeMarkup)
Sets whether model strings should be escaped.protected Component
setFlag(int flag, boolean set)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.protected Component
setIgnoreAttributeModifier(boolean ignore)
If true, all attribute modifiers will be ignoredComponent
setMarkup(IMarkupFragment markup)
Set the markup for the component.Component
setMarkupId(String markupId)
Sets this component's markup id to a user defined value.void
setMarkupIdImpl(Object markupId)
Set markup ID, which must be String or Integer<M extends Serializable>
ComponentsetMetaData(MetaDataKey<M> key, M object)
Sets the metadata for this component using the given key.Component
setOutputMarkupId(boolean output)
Sets whether or not component will output id attribute into the markup.Component
setOutputMarkupPlaceholderTag(boolean outputTag)
Render a placeholder tag when the component is not visible.void
setParent(MarkupContainer parent)
THIS IS A WICKET INTERNAL API.Component
setRenderBodyOnly(boolean renderTag)
If false the component's tag will be printed as well as its body (which is default).<C extends IRequestablePage>
voidsetResponsePage(Class<C> cls)
Sets the page that will respond to this request<C extends IRequestablePage>
voidsetResponsePage(Class<C> cls, PageParameters parameters)
Sets the page class and its parameters that will respond to this requestvoid
setResponsePage(IRequestablePage page)
Sets the page that will respond to this requestComponent
setVersioned(boolean versioned)
Component
setVisibilityAllowed(boolean allowed)
Sets whether or not this component is allowed to be visible.Component
setVisible(boolean visible)
Sets whether this component and any children are visible.void
success(Serializable message)
Registers an success feedback message for this componentString
toString()
Gets the string representation of this component.String
toString(boolean detailed)
<C extends Page>
CharSequenceurlFor(Class<C> pageClass, PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters.CharSequence
urlFor(IRequestHandler requestHandler)
Returns a URL that references the given request target.CharSequence
urlFor(ResourceReference resourceReference, PageParameters parameters)
Returns a URL that references a shared resource through the provided resource reference.CharSequence
urlForListener(Behavior behaviour, PageParameters parameters)
Gets a URL for the listener interface on a behavior (e.g.CharSequence
urlForListener(PageParameters parameters)
Gets a URL for thisIRequestListener
.<R,C extends MarkupContainer>
RvisitParents(Class<C> parentClass, IVisitor<C,R> visitor)
Traverses all parent components of the given class in this parentClass, calling the visitor's visit method at each one.<R,C extends MarkupContainer>
RvisitParents(Class<C> parentClass, IVisitor<C,R> visitor, IVisitFilter filter)
Traverses all parent components of the given class in this parentClass, calling the visitor's visit method at each one.void
warn(Serializable message)
Registers a warning feedback message for this component.protected <V> IModel<V>
wrap(IModel<V> model)
-
-
-
Field Detail
-
ENABLE
public static final Action ENABLE
Action used with IAuthorizationStrategy to determine whether a component is allowed to be enabled.If enabling is authorized, a component may decide by itself (typically using it's enabled property) whether it is enabled or not. If enabling is not authorized, the given component is marked disabled, regardless its enabled property.
When a component is not allowed to be enabled (in effect disabled through the implementation of this interface), Wicket will try to prevent model updates too. This is not completely fail safe, as constructs like:
User u = (User)getModelObject(); u.setName("got you there!");
can't be prevented. Indeed it can be argued that any model protection is best dealt with in your model objects to be completely secured. Wicket will catch all normal framework-directed use though.
-
PATH_SEPARATOR
public static final char PATH_SEPARATOR
Separator for component paths- See Also:
- Constant Field Values
-
PARENT_PATH
public static final String PARENT_PATH
Path segment that represents this component's parent- See Also:
- Constant Field Values
-
RENDER
public static final Action RENDER
Action used with IAuthorizationStrategy to determine whether a component and its children are allowed to be rendered.There are two uses for this method:
- The 'normal' use is for controlling whether a component is rendered without having any effect on the rest of the processing. If a strategy lets this method return 'false', then the target component and its children will not be rendered, in the same fashion as if that component had visibility property 'false'.
- The other use is when a component should block the rendering of the whole page. So
instead of 'hiding' a component, what we generally want to achieve here is that we force the
user to logon/give-credentials for a higher level of authorization. For this functionality,
the strategy implementation should throw a
AuthorizationException
, which will then be handled further by the framework.
-
FLAG_RESERVED1
protected static final int FLAG_RESERVED1
Reserved subclass-definable flag bit- See Also:
- Constant Field Values
-
FLAG_RESERVED2
protected static final int FLAG_RESERVED2
Reserved subclass-definable flag bit- See Also:
- Constant Field Values
-
FLAG_RESERVED3
protected static final int FLAG_RESERVED3
Reserved subclass-definable flag bit- See Also:
- Constant Field Values
-
FLAG_RESERVED4
protected static final int FLAG_RESERVED4
Reserved subclass-definable flag bit- See Also:
- Constant Field Values
-
FLAG_RESERVED5
protected static final int FLAG_RESERVED5
Reserved subclass-definable flag bit- See Also:
- Constant Field Values
-
FLAG_INITIALIZED
protected static final int FLAG_INITIALIZED
onInitialize called- See Also:
- Constant Field Values
-
FLAG_RESERVED8
protected static final int FLAG_RESERVED8
Reserved subclass-definable flag bit- See Also:
- Constant Field Values
-
RFLAG_CONTAINER_DEQUEING
protected static final short RFLAG_CONTAINER_DEQUEING
- See Also:
- Constant Field Values
-
RFLAG_CONTAINER_HAS_REMOVALS
protected static final short RFLAG_CONTAINER_HAS_REMOVALS
This flag tracks if removals have been set on this component. Clearing this key is an expensive operation. With this flag this expensive call can be avoided.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Component
public Component(String id)
Constructor. All components have names. A component's id cannot be null. This is the minimal constructor of component. It does not register a model.- Parameters:
id
- The non-null id of this component- Throws:
WicketRuntimeException
- Thrown if the component has been given a null id.
-
Component
public Component(String id, IModel<?> model)
Constructor. All components have names. A component's id cannot be null. This constructor includes a model.- Parameters:
id
- The non-null id of this componentmodel
- The component's model- Throws:
WicketRuntimeException
- Thrown if the component has been given a null id.
-
-
Method Detail
-
getMarkup
public IMarkupFragment getMarkup()
Get the Markup associated with the Component. If not subclassed, the parent container is asked to return the markup of this child component. Components like Panel and Border should return the "calling" markup fragment, e.g.<span wicket:id="myPanel">body</span>
. You may use Panel/Border/Enclosure.getMarkup(null) to return the associated markup file. And Panel/Border/Enclosure.getMarkup(child) will search the child in the appropriate markup fragment.- Returns:
- The markup fragment
- See Also:
MarkupContainer.getMarkup(Component)
-
getMarkupIdFromMarkup
public final String getMarkupIdFromMarkup()
- Returns:
- The 'id' attribute from the associated markup tag
-
setMarkup
public final Component setMarkup(IMarkupFragment markup)
Set the markup for the component. Note that the component's markup variable is transient and thus must only be used for one render cycle. E.g. auto-component are using it. You may also it if you subclassed getMarkup().- Parameters:
markup
-
-
onConfigure
protected void onConfigure()
Called on all components before any component is rendered. This method should be used to configure such things as visibility and enabled flags.Overrides must call
super.onConfigure()
, usually before any other codeNOTE: Component hierarchy should not be modified inside this method, instead it should be done in
onBeforeRender()
NOTE: Why this method is preferrable to directly overriding
isVisible()
andisEnabled()
? Because those methods are called multiple times even for processing of a single request. If they contain expensive logic they can slow down the response time of the entire page. Further, overriding those methods directly on form components may lead to inconsistent or unexpected state depending on when those methods are called in the form processing workflow. It is a better practice to push changes to state rather than pull.NOTE: If component's visibility or another property depends on another component you may call
other.configure()
followed byother.isVisible()
as mentioned inconfigure()
javadoc.NOTE: Why should
onBeforeRender()
not be used for this? Because if a component's visibility is controlled insideonBeforeRender()
, once invisible the component will never become visible again.
-
onInitialize
protected void onInitialize()
This method is meant to be used as an alternative to initialize components. Usually the component's constructor is used for this task, but sometimes a component cannot be initialized in isolation, it may need to access its parent component or its markup in order to fully initialize. This method is invoked once per component's lifecycle when a path exists from this component to thePage
thus providing the component with an atomic callback when the component's environment is built out.Overrides must call super#
onInitialize()
. Usually this should be the first thing an override does, much like a constructor.Parent containers are guaranteed to be initialized before their children
It is safe to use
getPage()
in this methodNOTE:The timing of this call is not precise, the contract is that it is called sometime before
onBeforeRender()
.
-
isInitialized
public final boolean isInitialized()
Checks if the component has been initialized -onInitialize()
has been called- Returns:
true
if component has been initialized
-
internalInitialize
public void internalInitialize()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Used to callonInitialize()
-
beforeRender
public final void beforeRender()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Called on all components before any component is rendered. Calls hooksconfigure()
and (if visible)onBeforeRender()
and delegates tobeforeRender()
of all child components.
-
configure
public final void configure()
TriggersonConfigure()
to be invoked on this component if it has not already during this request.This method should be invoked before any calls to
isVisible()
orisEnabled()
. Usually this method will be called by the framework before the component is rendered and so users should not need to call it; however, in cases where visibility or enabled or other state of one component depends on the state of another this method should be manually invoked on the other component by the user. EG to link visiliby of two markup containers the following should be done:final WebMarkupContainer source=new WebMarkupContainer("a") { protected void onConfigure() { setVisible(Math.rand()>0.5f); } }; WebMarkupContainer linked=new WebMarkupContainer("b") { protected void onConfigure() { source.configure(); // make sure source is configured setVisible(source.isVisible()); } }
-
continueToOriginalDestination
public final void continueToOriginalDestination()
Redirects to any intercept page previously specified by a call toredirectToInterceptPage(Page)
. The redirect is done by throwing an exception. If there is no intercept page no exception will be thrown and the program flow will continue uninterrupted. Example:add(new Link("login") { protected void onClick() { if (authenticate()) { continueToOriginalDestination(); // if we reach this line there was no intercept page, so go to home page setResponsePage(WelcomePage.class); } } });
- See Also:
redirectToInterceptPage(Page)
-
clearOriginalDestination
public final void clearOriginalDestination()
Clears any data about previously intercepted page.
-
debug
public final void debug(Serializable message)
Registers a debug feedback message for this component- Specified by:
debug
in interfaceIFeedbackContributor
- Parameters:
message
- The feedback message
-
detach
public final void detach()
Detaches the component. This is called at the end of the request for all the pages that are touched in that request.- Specified by:
detach
in interfaceIRequestableComponent
-
detachModels
public void detachModels()
Detaches all models
-
error
public final void error(Serializable message)
Registers an error feedback message for this component- Specified by:
error
in interfaceIFeedbackContributor
- Parameters:
message
- The feedback message
-
fatal
public final void fatal(Serializable message)
Registers a fatal feedback message for this component- Specified by:
fatal
in interfaceIFeedbackContributor
- Parameters:
message
- The feedback message
-
findParent
public final <Z> Z findParent(Class<Z> c)
Finds the first container parent of this component of the given class.- Type Parameters:
Z
- type of parent- Parameters:
c
- MarkupContainer class to search for- Returns:
- First container parent that is an instance of the given class, or null if none can be found
-
findParentWithAssociatedMarkup
public final MarkupContainer findParentWithAssociatedMarkup()
- Returns:
- The nearest markup container with associated markup
-
getApplication
public final Application getApplication()
Gets interface to application that this component is a part of.- Returns:
- The application associated with the session that this component is in.
- See Also:
Application
-
getClassRelativePath
public final String getClassRelativePath()
- Returns:
- A path of the form [page-class-name]:[page-relative-path]
- See Also:
getPageRelativePath()
-
getConverter
public <C> IConverter<C> getConverter(Class<C> type)
Get the converter that should be used by this component, delegates tocreateConverter(Class)
and then to the application'sIConverterLocator
.- Specified by:
getConverter
in interfaceIConverterLocator
- Type Parameters:
C
- The object to convert from and to String- Parameters:
type
- The type to convert to- Returns:
- The converter that should be used by this component
-
createConverter
protected IConverter<?> createConverter(Class<?> type)
Factory method for converters to be used by this component, returnsnull
by default.- Parameters:
type
- The type to convert to- Returns:
- a converter to be used by this component
-
getEscapeModelStrings
public final boolean getEscapeModelStrings()
Gets whether model strings should be escaped.- Returns:
- Returns whether model strings should be escaped
-
getId
public String getId()
Gets the id of this component.- Specified by:
getId
in interfaceIRequestableComponent
- Returns:
- The id of this component
-
getInnermostModel
public final IModel<?> getInnermostModel()
- Returns:
- Innermost model for this component
-
getLocale
public Locale getLocale()
Gets the locale for this component. By default, it searches its parents for a locale. If no parents (it's a recursive search) returns a locale, it gets one from the session.- Returns:
- The locale to be used for this component
- See Also:
Session.getLocale()
-
getLocalizer
public final Localizer getLocalizer()
Convenience method to provide easy access to the localizer object within any component.- Returns:
- The localizer object
-
getMarkupTag
protected final ComponentTag getMarkupTag()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Get the first component tag in the associated markup- Returns:
- first component tag
-
getMarkupAttributes
public final ValueMap getMarkupAttributes()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Get a copy of the markup's attributes which are associated with the component.Modifications to the map returned don't change the tags attributes. It is just a copy.
Note: The component must have been added (directly or indirectly) to a container with an associated markup file (Page, Panel or Border).
- Returns:
- markup attributes
-
getMarkupIdImpl
public final Object getMarkupIdImpl()
Get the markupId- Returns:
- MarkupId
-
getMarkupId
public String getMarkupId(boolean createIfDoesNotExist)
Retrieves id by which this component is represented within the markup. This is either the id attribute set explicitly via a call tosetMarkupId(String)
, id attribute defined in the markup, or an automatically generated id - in that order.If no id is set and
createIfDoesNotExist
is false, this method will return null. Otherwise it will generate an id value which by default will be unique in the page. This is the preferred way as there is no chance of id collision. This will also enablesetOutputMarkupId(boolean)
.Note: This method should only be called after the component or its parent have been added to the page.
- Parameters:
createIfDoesNotExist
- When there is no existing markup id, determines whether it should be generated or whethernull
should be returned.- Returns:
- markup id of the component
-
getMarkupId
public String getMarkupId()
Retrieves id by which this component is represented within the markup. This is either the id attribute set explicitly via a call tosetMarkupId(String)
, id attribute defined in the markup, or an automatically generated id - in that order.If no explicit id is set this function will generate an id value that will be unique in the page. This is the preferred way as there is no chance of id collision. This will also enable
setOutputMarkupId(boolean)
.Note: This method should only be called after the component or its parent have been added to the page.
- Returns:
- markup id of the component
-
getMetaData
public final <M extends Serializable> M getMetaData(MetaDataKey<M> key)
Gets metadata for this component using the given key.- Specified by:
getMetaData
in interfaceIMetadataContext<Serializable,Component>
- Type Parameters:
M
- The type of the metadata.- Parameters:
key
- The key for the data- Returns:
- The metadata or null of no metadata was found for the given key
- See Also:
MetaDataKey
-
getDefaultModel
public final IModel<?> getDefaultModel()
Gets the model. It returns the object that wraps the backing model.- Returns:
- The model
-
getDefaultModelObject
public final Object getDefaultModelObject()
Gets the backing model object. Unlike getDefaultModel().getObject(), this method returns null for a null model.- Returns:
- The backing model object
-
getDefaultModelObjectAsString
public final String getDefaultModelObjectAsString()
Gets a model object as a string. Depending on the "escape model strings" flag of the component, the string is either HTML escaped or not. "HTML escaped" meaning that only HTML sensitive chars are escaped but not all none-ascii chars. Proper HTML encoding should be used instead. In case you really need a fully escaped model string you may callStrings.escapeMarkup(CharSequence, boolean, boolean)
on the model string returned.- Returns:
- Model object for this component as a string
- See Also:
Strings.escapeMarkup(CharSequence, boolean, boolean)
,getEscapeModelStrings()
-
getDefaultModelObjectAsString
public final String getDefaultModelObjectAsString(Object modelObject)
Gets a model object as a string. Depending on the "escape model strings" flag of the component, the string is either HTML escaped or not. "HTML escaped" meaning that only HTML sensitive chars are escaped but not all none-ascii chars. Proper HTML encoding should be used instead. In case you really need a fully escaped model string you may callStrings.escapeMarkup(CharSequence, boolean, boolean)
on the model string returned.- Parameters:
modelObject
- Model object to convert to string- Returns:
- The string
- See Also:
Strings.escapeMarkup(CharSequence, boolean, boolean)
,getEscapeModelStrings()
-
getOutputMarkupId
public final boolean getOutputMarkupId()
Gets whether or not component will output id attribute into the markup. id attribute will be set to the value returned fromgetMarkupId()
.- Returns:
- whether or not component will output id attribute into the markup
-
getOutputMarkupPlaceholderTag
public final boolean getOutputMarkupPlaceholderTag()
Gets whether or not an invisible component will render a placeholder tag.- Returns:
- true if a placeholder tag should be rendered
-
getPage
public final Page getPage()
Gets the page holding this component.- Specified by:
getPage
in interfaceIRequestableComponent
- Returns:
- The page holding this component
- Throws:
WicketRuntimeException
- Thrown if component is not yet attached to a Page.- See Also:
findPage()
-
getPageRelativePath
public final String getPageRelativePath()
Gets the path to this component relative to its containing page, i.e. without leading page id.- Specified by:
getPageRelativePath
in interfaceIRequestableComponent
- Returns:
- The path to this component relative to the page it is in
-
getParent
public final MarkupContainer getParent()
Gets any parent container, or null if there is none.- Specified by:
getParent
in interfaceIHierarchical<Component>
- Returns:
- Any parent container, or null if there is none
-
getPath
public final String getPath()
Gets this component's path.- Returns:
- Colon separated path to this component in the component hierarchy
-
getRenderBodyOnly
public final boolean getRenderBodyOnly()
If false the component's tag will be printed as well as its body (which is default). If true only the body will be printed, but not the component's tag.- Returns:
- If true, the component tag will not be printed
-
getRequest
public final Request getRequest()
- Returns:
- The request for this component's active request cycle
-
getRequestCycle
public final RequestCycle getRequestCycle()
Gets the active request cycle for this component- Returns:
- The request cycle
-
getResponse
public final Response getResponse()
- Returns:
- The response for this component's active request cycle
-
getSession
public Session getSession()
Gets the current Session object.- Returns:
- The Session that this component is in
-
getSizeInBytes
public long getSizeInBytes()
- Returns:
- Size of this Component in bytes. Returns
0
- if the size cannot be calculated for some reason
-
getString
public final String getString(String key)
- Parameters:
key
- Key of string resource in property file- Returns:
- The String
- See Also:
Localizer
-
getString
public final String getString(String key, IModel<?> model)
- Parameters:
key
- The resource keymodel
- The model- Returns:
- The formatted string
- See Also:
Localizer
-
getString
public final String getString(String key, IModel<?> model, String defaultValue)
- Parameters:
key
- The resource keymodel
- The modeldefaultValue
- A default value if the string cannot be found- Returns:
- The formatted string
- See Also:
Localizer
-
getStyle
public final String getStyle()
A convenience method to access the Sessions's style.- Returns:
- The style of this component respectively the style of the Session.
- See Also:
Session.getStyle()
-
getVariation
public String getVariation()
Gets the variation string of this component that will be used to look up markup for this component. Subclasses can override this method to define by an instance what markup variation should be picked up. By default it will return null or the value of a parent.- Returns:
- The variation of this component.
-
hasBeenRendered
public final boolean hasBeenRendered()
Gets whether this component was rendered at least once.- Returns:
- true if the component has been rendered before, false if it is merely constructed
-
getFeedbackMessages
public FeedbackMessages getFeedbackMessages()
Gets feedback messages for this component. This method will instantiate aFeedbackMessages
instance and add it to the component metadata, even when called on a component that has no feedback messages, to avoid the overhead usehasFeedbackMessage()
- Returns:
- feedback messages instance
-
hasErrorMessage
public final boolean hasErrorMessage()
- Returns:
- True if this component has an error message
-
hasFeedbackMessage
public final boolean hasFeedbackMessage()
- Returns:
- True if this component has some kind of feedback message
-
info
public final void info(Serializable message)
Registers an informational feedback message for this component- Specified by:
info
in interfaceIFeedbackContributor
- Parameters:
message
- The feedback message
-
success
public final void success(Serializable message)
Registers an success feedback message for this component- Specified by:
success
in interfaceIFeedbackContributor
- Parameters:
message
- The feedback message
-
isActionAuthorized
public final boolean isActionAuthorized(Action action)
Authorizes an action for a component.- Parameters:
action
- The action to authorize- Returns:
- True if the action is allowed
- Throws:
AuthorizationException
- Can be thrown by implementation if action is unauthorized
-
isEnableAllowed
public final boolean isEnableAllowed()
- Returns:
- true if this component is authorized to be enabled, false otherwise
-
isEnabled
public boolean isEnabled()
Gets whether this component is enabled. Specific components may decide to implement special behavior that uses this property, like web form components that add a disabled='disabled' attribute when enabled is false.- Returns:
- Whether this component is enabled.
-
isRenderAllowed
public final boolean isRenderAllowed()
Checks the security strategy if theRENDER
action is allowed on this component- Returns:
- true if
RENDER
action is allowed, false otherwise
-
isStateless
public final boolean isStateless()
Returns if the component is stateless or not. It checks the stateless hint if that is false it returns directly false. If that is still true it checks all its behaviors if they can be stateless.- Returns:
- whether the component is stateless.
-
isVersioned
public boolean isVersioned()
- Returns:
true
if this component should notify its holding page about changes in its state. If aPage
is not versioned then it wont track changes in its components and will use the samePage.getPageId()
during its lifetime
-
isVisible
public boolean isVisible()
Gets whether this component and any children are visible.WARNING: this method can be called multiple times during a request. If you override this method, it is a good idea to keep it cheap in terms of processing. Alternatively, you can call
setVisible(boolean)
.- Returns:
- True if component and any children are visible
-
isVisibleInHierarchy
public final boolean isVisibleInHierarchy()
Checks if the component itself and all its parents are visible.- Returns:
- true if the component and all its parents are visible.
-
markRendering
public final void markRendering(boolean setRenderingFlag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Sets the RENDERING flag and removes the PREPARED_FOR_RENDER flag on component and it's children.- Parameters:
setRenderingFlag
- if this is false only the PREPARED_FOR_RENDER flag is removed from component, the RENDERING flag is not set.
-
modelChanged
public final void modelChanged()
Called to indicate that the model content for this component has been changed
-
modelChanging
public final void modelChanging()
Called to indicate that the model content for this component is about to change
-
redirectToInterceptPage
public final void redirectToInterceptPage(Page page)
Redirects browser to an intermediate page such as a sign-in page. The current request's URL is saved for future use by methodcontinueToOriginalDestination()
; only use this method when you plan to continue to the current URL at some later time; otherwise just set a new response page.- Parameters:
page
- The sign in page- See Also:
setResponsePage(Class)
,setResponsePage(IRequestablePage)
,setResponsePage(Class, PageParameters)
,continueToOriginalDestination()
-
remove
public final void remove()
Removes this component from its parent. It's important to remember that a component that is removed cannot be referenced from the markup still.You must not use this method in your callback to any of the
MarkupContainer.visitChildren(IVisitor)
methods. See WICKET-3329.
-
renderPart
public final void renderPart()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!Renders this component as a part of a response - the caller has to make sure that this component is prepared for render.
- See Also:
beforeRender()
-
render
public final void render()
Render this component and all its children. Always calls hookonAfterRender()
regardless of any exception.
-
renderPlaceholderTag
protected void renderPlaceholderTag(ComponentTag tag, Response response)
Renders a placeholder tag for the component when it is invisible andsetOutputMarkupPlaceholderTag(boolean)
has been called withtrue
.- Parameters:
tag
- component tagresponse
- response
-
getAjaxRegionMarkupId
public final String getAjaxRegionMarkupId()
Returns the id of the markup region that will be updated via ajax. This can be different to the markup id of the component if aIAjaxRegionMarkupIdProvider
behavior has been added.- Returns:
- the markup id of the region to be updated via ajax.
-
internalRenderComponent
protected final void internalRenderComponent()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!Renders the component at the current position in the given markup stream. The method onComponentTag() is called to allow the component to mutate the start tag. The method onComponentTagBody() is then called to permit the component to render its body.
-
rendered
public final void rendered()
Called to indicate that a component has been rendered. This method should only very rarely be called at all. Some components may render its children without calling render() on them. These components need to call rendered() to indicate that its child components were actually rendered, the framework would think they had never been rendered, and in development mode this would result in a runtime exception.
-
getMarkupSourcingStrategy
protected final IMarkupSourcingStrategy getMarkupSourcingStrategy()
Get the markup sourcing strategy for the component. If null,newMarkupSourcingStrategy()
will be called.- Returns:
- Markup sourcing strategy
-
newMarkupSourcingStrategy
protected IMarkupSourcingStrategy newMarkupSourcingStrategy()
IfgetMarkupSourcingStrategy()
returns null, this method will be called. By default it returns null, which means that a default markup strategy will be attached to the component.Please note that markup source strategies are not persisted. Instead they get re-created by calling this method again. That's ok since markup sourcing strategies usually do not maintain a state.
- Returns:
- Markup sourcing strategy
-
internalRenderHead
public void internalRenderHead(HtmlHeaderContainer container)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Print to the web response what ever the component wants to contribute to the head section. Make sure that all attached behaviors are asked as well.NOT intended for overriding by framework clients. Rather, use
renderHead(org.apache.wicket.markup.head.IHeaderResponse)
- Parameters:
container
- The HtmlHeaderContainer
-
replaceWith
public Component replaceWith(Component replacement)
Replaces this component with another. The replacing component must have the same component id as this component. This method serves as a shortcut tothis.getParent().replace(replacement)
and provides a better context for errors.Usage:
component = component.replaceWith(replacement);
- Parameters:
replacement
- component to replace this one- Returns:
- the component which replaced this one
- Since:
- 1.2.1
-
sameInnermostModel
public final boolean sameInnermostModel(Component component)
- Parameters:
component
- The component to compare with- Returns:
- True if the given component's model is the same as this component's model.
-
sameInnermostModel
public final boolean sameInnermostModel(IModel<?> model)
- Parameters:
model
- The model to compare with- Returns:
- True if the given component's model is the same as this component's model.
-
setEnabled
public final Component setEnabled(boolean enabled)
Sets whether this component is enabled. Specific components may decide to implement special behavior that uses this property, like web form components that add a disabled='disabled' attribute when enabled is false. If it is not enabled, it will not be allowed to call any listener method on it (e.g. Link.onClick) and the model object will be protected (for the common use cases, not for programmer's misuse)- Parameters:
enabled
- whether this component is enabled- Returns:
- This
-
setEscapeModelStrings
public final Component setEscapeModelStrings(boolean escapeMarkup)
Sets whether model strings should be escaped.- Parameters:
escapeMarkup
- True is model strings should be escaped- Returns:
- This
-
setMarkupIdImpl
public final void setMarkupIdImpl(Object markupId)
Set markup ID, which must be String or Integer- Parameters:
markupId
-
-
setMarkupId
public Component setMarkupId(String markupId)
Sets this component's markup id to a user defined value. It is up to the user to ensure this value is unique.The recommended way is to let wicket generate the value automatically, this method is here to serve as an override for that value in cases where a specific id must be used.
If null is passed in the user defined value is cleared and markup id value will fall back on automatically generated value
- Parameters:
markupId
- markup id value or null to clear any previous user defined value- Returns:
- this for chaining
- See Also:
getMarkupId()
-
setMetaData
public final <M extends Serializable> Component setMetaData(MetaDataKey<M> key, M object)
Sets the metadata for this component using the given key. If the metadata object is not of the correct type for the metadata key, an IllegalArgumentException will be thrown. For information on creating MetaDataKeys, seeMetaDataKey
.- Specified by:
setMetaData
in interfaceIMetadataContext<Serializable,Component>
- Type Parameters:
M
- The type of the metadata- Parameters:
key
- The singleton key for the metadataobject
- The metadata object- Throws:
IllegalArgumentException
- See Also:
MetaDataKey
-
setDefaultModel
public Component setDefaultModel(IModel<?> model)
Sets the given model.WARNING: DO NOT OVERRIDE THIS METHOD UNLESS YOU HAVE A VERY GOOD REASON FOR IT. OVERRIDING THIS MIGHT OPEN UP SECURITY LEAKS AND BREAK BACK-BUTTON SUPPORT.
- Parameters:
model
- The model- Returns:
- This
-
setDefaultModelObject
public final Component setDefaultModelObject(Object object)
Sets the backing model object. UnlikegetDefaultModel().setObject(object)
, this method checks authorisation and model comparator, and invokesmodelChanging
andmodelChanged
if the value really changes.- Parameters:
object
- The object to set- Returns:
- This
- Throws:
IllegalStateException
- If the component has neither its own model nor any of its parents usesIComponentInheritedModel
-
setOutputMarkupId
public final Component setOutputMarkupId(boolean output)
Sets whether or not component will output id attribute into the markup. id attribute will be set to the value returned fromgetMarkupId()
.- Parameters:
output
- True if the component will output the id attribute into markup. Please note that the default behavior is to use the same id as the component. This means that your component must begin with [a-zA-Z] in order to generate a valid markup id according to: http://www.w3.org/TR/html401/types.html#type-name- Returns:
- this for chaining
-
setOutputMarkupPlaceholderTag
public final Component setOutputMarkupPlaceholderTag(boolean outputTag)
Render a placeholder tag when the component is not visible. The tag is of form: <componenttag hidden="" id="markupid"/>. This method will also callsetOutputMarkupId(true)
. This is useful, for example, in ajax situations where the component starts out invisible and then becomes visible through an ajax update. With a placeholder tag already in the markup you do not need to repaint this component's parent, instead you can repaint the component directly. When this method is called with parameterfalse
the outputmarkupid flag is not reverted to false.- Parameters:
outputTag
-- Returns:
- this for chaining
-
setRenderBodyOnly
public final Component setRenderBodyOnly(boolean renderTag)
If false the component's tag will be printed as well as its body (which is default). If true only the body will be printed, but not the component's tag.- Parameters:
renderTag
- If true, the component tag will not be printed- Returns:
- This
-
setResponsePage
public final <C extends IRequestablePage> void setResponsePage(Class<C> cls)
Sets the page that will respond to this request- Type Parameters:
C
-- Parameters:
cls
- The response page class- See Also:
RequestCycle.setResponsePage(Class)
-
setResponsePage
public final <C extends IRequestablePage> void setResponsePage(Class<C> cls, PageParameters parameters)
Sets the page class and its parameters that will respond to this request- Type Parameters:
C
-- Parameters:
cls
- The response page classparameters
- The parameters for this bookmarkable page.- See Also:
RequestCycle.setResponsePage(Class, PageParameters)
-
setResponsePage
public final void setResponsePage(IRequestablePage page)
Sets the page that will respond to this request- Parameters:
page
- The response page- See Also:
RequestCycle.setResponsePage(org.apache.wicket.request.component.IRequestablePage)
-
setVersioned
public Component setVersioned(boolean versioned)
- Parameters:
versioned
- True to turn on versioning for this component, false to turn it off for this component and any children.- Returns:
- This
-
setVisible
public final Component setVisible(boolean visible)
Sets whether this component and any children are visible.- Parameters:
visible
- True if this component and any children should be visible- Returns:
- This
-
toString
public String toString(boolean detailed)
- Parameters:
detailed
- True if a detailed string is desired- Returns:
- The string
-
urlFor
public final <C extends Page> CharSequence urlFor(Class<C> pageClass, PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters. Since the URL which is returned contains all information necessary to instantiate and render the page, it can be stored in a user's browser as a stable bookmark.- Type Parameters:
C
-- Parameters:
pageClass
- Class of pageparameters
- Parameters to page- Returns:
- Bookmarkable URL to page
- See Also:
RequestCycle.urlFor(Class, org.apache.wicket.request.mapper.parameter.PageParameters)
-
urlForListener
public final CharSequence urlForListener(Behavior behaviour, PageParameters parameters)
Gets a URL for the listener interface on a behavior (e.g.IRequestListener
onAjaxPagingNavigationBehavior
).- Parameters:
behaviour
- The behavior that the URL should point toparameters
- The parameters that should be rendered into the urls- Returns:
- The URL
-
urlFor
public final CharSequence urlFor(IRequestHandler requestHandler)
Returns a URL that references the given request target.- Parameters:
requestHandler
- the request target to reference- Returns:
- a URL that references the given request target
- See Also:
RequestCycle.urlFor(IRequestHandler)
-
urlForListener
public final CharSequence urlForListener(PageParameters parameters)
Gets a URL for thisIRequestListener
.- Parameters:
parameters
- The parameters that should be rendered into the URL- Returns:
- The URL
- See Also:
RequestCycle.urlFor(IRequestHandler)
-
urlFor
public final CharSequence urlFor(ResourceReference resourceReference, PageParameters parameters)
Returns a URL that references a shared resource through the provided resource reference.- Parameters:
resourceReference
- The resource referenceparameters
- parameters ornull
if none- Returns:
- The url for the shared resource
- See Also:
RequestCycle.urlFor(IRequestHandler)
-
visitParents
public final <R,C extends MarkupContainer> R visitParents(Class<C> parentClass, IVisitor<C,R> visitor)
Traverses all parent components of the given class in this parentClass, calling the visitor's visit method at each one.- Type Parameters:
R
- the type of the result object- Parameters:
parentClass
- Classvisitor
- The visitor to call at each parent of the given type- Returns:
- First non-null value returned by visitor callback
-
visitParents
public final <R,C extends MarkupContainer> R visitParents(Class<C> parentClass, IVisitor<C,R> visitor, IVisitFilter filter)
Traverses all parent components of the given class in this parentClass, calling the visitor's visit method at each one.- Type Parameters:
R
- the type of the result object- Parameters:
parentClass
- the class of the parent componentvisitor
- The visitor to call at each parent of the given typefilter
- a filter that adds an additional logic to the condition whether a parent container matches- Returns:
- First non-null value returned by visitor callback
-
warn
public final void warn(Serializable message)
Registers a warning feedback message for this component.- Specified by:
warn
in interfaceIFeedbackContributor
- Parameters:
message
- The feedback message
-
addStateChange
protected final void addStateChange()
TODO WICKET-NG rename to something more useful - like componentChanged(), this method used to be called with a Change object Adds state change to page.
-
checkComponentTag
protected final void checkComponentTag(ComponentTag tag, String name)
Checks whether the given type has the expected name.- Parameters:
tag
- The tag to checkname
- The expected tag name- Throws:
MarkupException
- Thrown if the tag is not of the right name
-
checkComponentTagAttribute
protected final void checkComponentTagAttribute(ComponentTag tag, String key, String... values)
Checks that a given tag has a required attribute value.- Parameters:
tag
- The tagkey
- The attribute keyvalues
- The required value for the attribute key- Throws:
MarkupException
- Thrown if the tag does not have the required attribute value
-
checkHierarchyChange
protected void checkHierarchyChange(Component component)
Checks whether the hierarchy may be changed at all, and throws an exception if this is not the case.- Parameters:
component
- the component which is about to be added or removed
-
detachModel
protected void detachModel()
Detaches the model for this component if it is detachable.
-
exceptionMessage
protected final String exceptionMessage(String message)
Suffixes an exception message with useful information about this. component.- Parameters:
message
- The message- Returns:
- The modified message
-
findMarkupStream
protected final MarkupStream findMarkupStream()
Finds the markup stream for this component.- Returns:
- The markup stream for this component. Since a Component cannot have a markup stream, we ask this component's parent to search for it.
-
findPage
protected final Page findPage()
If this Component is a Page, returns self. Otherwise, searches for the nearest Page parent in the component hierarchy. If no Page parent can be found,null
is returned.- Returns:
- The Page or
null
if none can be found
-
getBehaviors
public <M extends Behavior> List<M> getBehaviors(Class<M> type)
Gets the subset of the currently coupledBehavior
s that are of the provided type as an unmodifiable list. Returns an empty list if there are no behaviors coupled to this component.- Type Parameters:
M
- A class derived from Behavior- Parameters:
type
- The type or null for all- Returns:
- The subset of the currently coupled behaviors that are of the provided type as an unmodifiable list
-
getFlag
protected final boolean getFlag(int flag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!- Parameters:
flag
- The flag to test- Returns:
- True if the flag is set
-
getRequestFlag
protected final boolean getRequestFlag(short flag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!- Parameters:
flag
- The flag to test- Returns:
- True if the flag is set
-
getInnermostModel
protected final IModel<?> getInnermostModel(IModel<?> model)
Finds the innermost IModel object for an IModel that might contain nested IModel(s).- Parameters:
model
- The model- Returns:
- The innermost (most nested) model
-
getModelComparator
public IModelComparator getModelComparator()
Gets the component's current model comparator. Implementations can be used for testing the current value of the components model data with the new value that is given.- Returns:
- the value defaultModelComparator
-
getStatelessHint
protected boolean getStatelessHint()
Returns whether the component can be stateless. Also the component behaviors must be stateless, otherwise the component will be treat as stateful. In order for page to be stateless (and not to be stored in session), all components (and component behaviors) must be stateless.- Returns:
- whether the component can be stateless
-
initModel
protected IModel<?> initModel()
Called when a null model is about to be retrieved in order to allow a subclass to provide an initial model.By default this implementation looks components in the parent chain owning a
IComponentInheritedModel
to provide a model for this component viaIComponentInheritedModel.wrapOnInheritance(Component)
.For example a
FormComponent
has the opportunity to instantiate a model on the fly using itsid
and the containingForm
's model, if the form holds aCompoundPropertyModel
.- Returns:
- The model
-
internalOnModelChanged
protected void internalOnModelChanged()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL OR OVERRIDE.Called anytime a model is changed via setModel or setModelObject.
-
isBehaviorAccepted
protected boolean isBehaviorAccepted(Behavior behavior)
Components are allowed to reject behavior modifiers.- Parameters:
behavior
-- Returns:
- False, if the component should not apply this behavior
-
isIgnoreAttributeModifier
protected final boolean isIgnoreAttributeModifier()
If true, all attribute modifiers will be ignored- Returns:
- True, if attribute modifiers are to be ignored
-
onAfterRender
protected void onAfterRender()
Called immediately after a component and all its children have been rendered, regardless of any exception.
-
onBeforeRender
protected void onBeforeRender()
Called on all visible components before any component is rendered.NOTE: If you override this, you *must* call super.onBeforeRender() within your implementation. Because this method is responsible for cascading
Changes to the component tree can be made only before calling super.onBeforeRender().onBeforeRender()
call to its children it is strongly recommended that super call is made at the end of the override.
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Processes the component tag. Overrides of this method most likely should call the super implementation.- Parameters:
tag
- Tag to modify
-
onComponentTagBody
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
Processes the body.- Parameters:
markupStream
- The markup streamopenTag
- The open tag for the body
-
onDetach
protected void onDetach()
Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.
-
onRemove
protected void onRemove()
Called to notify the component it is being removed from the component hierarchy Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.
-
onModelChanged
protected void onModelChanged()
Called anytime a model is changed after the change has occurred
-
onModelChanging
protected void onModelChanging()
Called anytime a model is changed, but before the change actually occurs
-
onRender
protected abstract void onRender()
Implementation that renders this component.
-
renderComponentTag
protected final void renderComponentTag(ComponentTag tag)
Writes a simple tag out to the response stream. Any components that might be referenced by the tag are ignored. Also undertakes any tag attribute modifications if they have been added to the component.- Parameters:
tag
- The tag to write
-
replaceComponentTagBody
protected final void replaceComponentTagBody(MarkupStream markupStream, ComponentTag tag, CharSequence body)
Replaces the body with the given one.- Parameters:
markupStream
- The markup stream to replace the tag body intag
- The tagbody
- The new markup
-
setAuto
protected final Component setAuto(boolean auto)
- Parameters:
auto
- True to put component into auto-add mode
-
setFlag
protected final Component setFlag(int flag, boolean set)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!- Parameters:
flag
- The flag to setset
- True to turn the flag on, false to turn it off
-
setIgnoreAttributeModifier
protected final Component setIgnoreAttributeModifier(boolean ignore)
If true, all attribute modifiers will be ignored- Parameters:
ignore
- If true, all attribute modifiers will be ignored- Returns:
- This
-
wrap
protected final <V> IModel<V> wrap(IModel<V> model)
- Type Parameters:
V
- The model type- Parameters:
model
- The model to wrap if need be- Returns:
- The wrapped model
-
get
public Component get(String path)
Gets the component at the given path.- Specified by:
get
in interfaceIRequestableComponent
- Parameters:
path
- Path to component- Returns:
- The component at the path
-
isAuto
public final boolean isAuto()
- Returns:
- True if this component or any of its parents is in auto-add mode
-
setParent
public final void setParent(MarkupContainer parent)
THIS IS A WICKET INTERNAL API. DO NOT USE IT. Sets the parent of a component. Typically what you really want is parent.add(child). Note that calling setParent() and not parent.add() will connect the child to the parent, but the parent will not know the child. This might not be a problem in some cases, but e.g. child.onDetach() will not be invoked (since the parent doesn't know it is his child).- Parameters:
parent
- The parent container
-
setVisibilityAllowed
public final Component setVisibilityAllowed(boolean allowed)
Sets whether or not this component is allowed to be visible. This method is meant to be used by components to control visibility of other components. A call tosetVisible(boolean)
will not always have a desired effect because that component may haveisVisible()
overridden. BothsetVisibilityAllowed(boolean)
andisVisibilityAllowed()
arefinal
so their contract is enforced always.- Parameters:
allowed
-- Returns:
this
for chaining
-
isVisibilityAllowed
public final boolean isVisibilityAllowed()
Gets whether or not visibility is allowed on this component. SeesetVisibilityAllowed(boolean)
for details.- Returns:
- true if this component is allowed to be visible, false otherwise.
-
determineVisibility
public final boolean determineVisibility()
Determines whether or not a component should be visible, taking into account all the factors:isVisible()
,isVisibilityAllowed()
,isRenderAllowed()
- Returns:
true
if the component should be visible,false
otherwise
-
isEnabledInHierarchy
public boolean isEnabledInHierarchy()
Calculates enabled state of the component taking its hierarchy into account. A component is enabled iff it is itself enabled (isEnabled()
andisEnableAllowed()
both returntrue
), and all of its parents are enabled.- Returns:
true
if this component is enabled
-
isRendering
public final boolean isRendering()
Says if the component is rendering currently.- Returns:
- true if this component is rendering, false otherwise.
-
canCallListener
public boolean canCallListener()
Checks whether or not anIRequestListener
can be invoked on this component. Usually components deny these invocations if they are either invisible or disabled in hierarchy.WARNING: be careful when overriding this method because it may open security holes - such as allowing a user to click on a link that should be disabled.
Example usecase for overriding: Suppose you are building an component that displays images. The component generates a callback to itself using
IRequestListener
interface and uses this callback to stream image data. If such a component is placed inside a disabledWebMarkupContainer
we still want to allow the invocation of the request listener callback method so that image data can be streamed. Such a component would override this method and return true.- Returns:
- true iff the listener method can be invoked on this component
-
renderHead
public void renderHead(IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.- Specified by:
renderHead
in interfaceIHeaderContributor
- Parameters:
response
- Response object
-
onEvent
public void onEvent(IEvent<?> event)
Called when an event is sent to this sink- Specified by:
onEvent
in interfaceIEventSink
-
send
public final <T> void send(IEventSink sink, Broadcast type, T payload)
Sends an event- Specified by:
send
in interfaceIEventSource
- Type Parameters:
T
- type of payload- Parameters:
sink
- object that will receive the eventtype
- if the object that receives the event needs to broadcast it to others, this is the type of broadcast that should be usedpayload
- event payload
-
remove
public Component remove(Behavior... behaviors)
Removes behavior from component- Parameters:
behaviors
- behaviors to remove- Returns:
- this (to allow method call chaining)
-
getBehaviorById
public final Behavior getBehaviorById(int id)
Gets the behavior for the specified id- Specified by:
getBehaviorById
in interfaceIRequestableComponent
- Returns:
- behavior or
null
if none
-
getBehaviorId
public final int getBehaviorId(Behavior behavior)
Gets a stable id for the specified non-temporary behavior. The id remains stable from the point this method is first called for the behavior until the behavior has been removed from the component. This includes from one request to the next, when the component itself is retained for the next request (i.e. is stateful). Note that the bookkeeping required for these stable ids increases the memory footprint of the component.- Specified by:
getBehaviorId
in interfaceIRequestableComponent
- Returns:
- a stable id for the specified behavior
-
add
public Component add(Behavior... behaviors)
Adds a behavior modifier to the component.- Parameters:
behaviors
- The behavior modifier(s) to be added- Returns:
- this (to allow method call chaining)
-
getBehaviors
public final List<? extends Behavior> getBehaviors()
Gets the currently coupledBehavior
s as an unmodifiable list. Returns an empty list rather than null if there are no behaviors coupled to this component.- Returns:
- The currently coupled behaviors as an unmodifiable list
-
canCallListenerAfterExpiry
public boolean canCallListenerAfterExpiry()
- Specified by:
canCallListenerAfterExpiry
in interfaceIRequestableComponent
- Returns:
true
if it is save to call anIRequestListener
on this component when the owner page is freshly created after expiration
-
onReAdd
protected void onReAdd()
This method is called whenever a component is re-added to the page's component tree, if it had been removed at some earlier time, i.e., if it is already initialized (seeisInitialized()
). This is similar to onInitialize, but only comes after the component has been removed and then added again:- onInitialize is only called the very first time a component is added
- onReAdd is not called the first time, but every time it is re-added after having been removed
-
-