org.apache.wicket
public abstract class Component extends Object implements IClusterable, IConverterLocator, IRequestableComponent, IHeaderContributor, IHierarchical<Component>, IEventSink, IEventSource
MarkupContainer
that holds the Component, but
does not have to be globally unique or unique within a Page's component hierarchy.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 call getPageRelativePath()
.
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.
WicketFilter
. An associated Application object creates Session
,
Request
and Response
objects for use by a given Component in updating its model
and rendering a response. These objects are stored inside a container called RequestCycle
which is accessible via getRequestCycle()
. The convenience methods
getRequest()
, getResponse()
and
getSession()
provide easy access to the contents of this container.IRequestListener
on an
existing Component (or one of its Behavior
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. See Form
for an
example of a component which listens for events via IFormSubmitListener
.onConfigure()
(regardless whether they are visible or not) and onBeforeRender()
(if visible only) . render()
, which calls
subclass implementation code contained in onRender()
. Once this phase begins, a
Component becomes immutable. Attempts to alter the Component will result in a
WicketRuntimeException.onDetach()
or more specifically
detachModels()
if they keep references to models beside the default model.setVisible(boolean)
) it will
not render a response (nor will their children).setEnabled(boolean)
when rendering, and in case of a FormComponent
will not not
update its model while the request is handled.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,
see FormComponent.updateModel()
. Since the IModel interface is a wrapper around another
object, a convenience method getDefaultModelObject()
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. setDefaultModel(IModel)
. In neither case a model can be created on demand with
initModel()
.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.getLocale()
, which
delegates to its parent's locale, finally consulting the Session
's locale.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.getVariation()
returnss "NorthSea", than the
resources are given the names suffixed with "_ocean_NorthSea".getLocalizer()
.
The convenience methods getString(String key)
and
getString(String key, IModel model)
wrap the identical methods on the
Application Localizer for easy access in Components.debug(Serializable)
,
info(Serializable)
, warn(Serializable)
,
error(java.io.Serializable)
and fatal(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 with getFeedbackMessages()
.setVersioned(boolean)
method. The versioning participation of a given Component
can be retrieved with isVersioned()
.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.getApplication()
method provides convenient access to the
Application
for a Component.IAuthorizationStrategy
which
controls instantiation, visibility and enabling. See SimplePageAuthorizationStrategy
for
a simple implementation.Modifier and Type | Field and Description |
---|---|
static Action |
ENABLE
Action used with IAuthorizationStrategy to determine whether a component is allowed to be
enabled.
|
protected static int |
FLAG_INITIALIZED
onInitialize called
|
protected static int |
FLAG_REMOVING_FROM_HIERARCHY
True when a component is being removed from the hierarchy
|
protected static int |
FLAG_RESERVED1
Reserved subclass-definable flag bit
|
protected static int |
FLAG_RESERVED2
Reserved subclass-definable flag bit
|
protected static int |
FLAG_RESERVED3
Reserved subclass-definable flag bit
|
protected static int |
FLAG_RESERVED4
Reserved subclass-definable flag bit
|
protected static int |
FLAG_RESERVED5
Reserved subclass-definable flag bit
|
protected static int |
FLAG_RESERVED8
Reserved subclass-definable flag bit
|
static String |
PARENT_PATH
Path segment that represents this component's parent
|
static char |
PATH_SEPARATOR
Separator for component paths
|
static Action |
RENDER
Action used with IAuthorizationStrategy to determine whether a component and its children are
allowed to be rendered.
|
Constructor and Description |
---|
Component(String id)
Constructor.
|
Component(String id,
IModel<?> model)
Constructor.
|
Modifier and Type | Method and 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 |
afterRender()
Called on every component after the page is rendered.
|
void |
beforeRender()
Called for every component when the page is getting to be rendered.
|
boolean |
canCallListenerInterface(Method method)
Checks whether or not a listener method can be invoked on this component.
|
protected void |
checkComponentTag(ComponentTag tag,
String name)
Checks whether the given type has the expected name.
|
protected void |
checkComponentTagAttribute(ComponentTag tag,
String key,
String value)
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()
Triggers
onConfigure() 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 to redirectToInterceptPage.
|
void |
debug(Serializable message)
Registers a debug feedback message for this component
|
void |
detach()
Detaches the component.
|
protected void |
detachModel()
Detaches the model for this component if it is detachable.
|
void |
detachModels()
Detaches all models
|
boolean |
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 component
|
protected String |
exceptionMessage(String message)
Suffixes an exception message with useful information about this.
|
void |
fatal(Serializable message)
Registers a fatal feedback message for this component
|
protected 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 id
|
int |
getBehaviorId(Behavior behavior)
Gets a stable id for the specified behavior.
|
List<? extends Behavior> |
getBehaviors()
Gets the currently coupled
Behavior s as a unmodifiable list. |
<M extends Behavior> |
getBehaviors(Class<M> type)
Gets the subset of the currently coupled
Behavior s that are of the provided type as
an unmodifiable list. |
String |
getClassRelativePath() |
<C> IConverter<C> |
getConverter(Class<C> type)
Gets the converter that should be used by this component.
|
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 IS WICKET INTERNAL ONLY.
|
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 markupId
|
protected IMarkupSourcingStrategy |
getMarkupSourcingStrategy()
Get the markup sourcing strategy for the component.
|
<M extends Serializable> |
getMetaData(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 component
|
protected 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 component
|
protected 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 PUBLIC API, DO NOT CALL IT
Used to call
onInitialize() |
protected void |
internalOnModelChanged()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
internalPrepareForRender(boolean setRenderingFlag)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
internalRenderComponent()
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 ignored
|
boolean |
isRenderAllowed()
Checks the security strategy if the
RENDER action is allowed on this
component |
boolean |
isRendering()
Says if the component is rendering or not checking the corresponding flag.
|
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 changed
|
void |
modelChanging()
Called to indicate that the model content for this component is about to change
|
protected IMarkupSourcingStrategy |
newMarkupSourcingStrategy()
If
getMarkupSourcingStrategy() returns null, this method will be called. |
protected void |
onAfterRender()
Called just after a component is rendered.
|
protected void |
onAfterRenderChildren() |
protected void |
onBeforeRender()
Called just before a component is rendered only if the component is visible.
|
protected void |
onComponentTag(ComponentTag tag)
Processes the component tag.
|
void |
onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag)
Processes the body.
|
protected void |
onConfigure()
Called once per request on components before they are about to be 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 sink
|
protected 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 occurred
|
protected void |
onModelChanging()
Called anytime a model is changed, but before the change actually occurs
|
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
(see
isInitialized() ). |
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 |
prepareForRender()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
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 component
|
void |
render()
Render the Component.
|
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(Component component,
IHeaderResponse response)
CAUTION: this method is not meant to be overridden like it was in wicket 1.4 when
implementing
IHeaderContributor . |
void |
renderHead(HtmlHeaderContainer container)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
renderHead(IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.
|
protected void |
renderPlaceholderTag(ComponentTag tag,
Response response)
Renders a placeholder tag for the component when it is invisible and
setOutputMarkupPlaceholderTag(boolean) has been called with true . |
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 event
|
protected void |
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 void |
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 ignored
|
void |
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> void |
setMetaData(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).
|
protected void |
setRequestFlag(short flag,
boolean set)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
<C extends IRequestablePage> |
setResponsePage(Class<C> cls)
Sets the page that will respond to this request
|
<C extends IRequestablePage> |
setResponsePage(Class<C> cls,
PageParameters parameters)
Sets the page class and its parameters that will respond to this request
|
void |
setResponsePage(Page page)
Sets the page that will respond to this request
|
Component |
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 component
|
String |
toString()
Gets the string representation of this component.
|
String |
toString(boolean detailed) |
CharSequence |
urlFor(Behavior behaviour,
RequestListenerInterface listener,
PageParameters parameters)
Gets a URL for the listener interface on a behavior (e.g.
|
<C extends Page> |
urlFor(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(RequestListenerInterface listener,
PageParameters parameters)
Gets a URL for the listener interface (e.g.
|
CharSequence |
urlFor(ResourceReference resourceReference,
PageParameters parameters)
Returns a URL that references a shared resource through the provided resource reference.
|
<R,C extends MarkupContainer> |
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.
|
<R,C extends MarkupContainer> |
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.
|
void |
warn(Serializable message)
Registers a warning feedback message for this component.
|
protected <V> IModel<V> |
wrap(IModel<V> model) |
public static final Action ENABLE
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.
public static final char PATH_SEPARATOR
public static final String PARENT_PATH
public static final Action RENDER
There are two uses for this method:
AuthorizationException
, which will then be
handled further by the framework.protected static final int FLAG_RESERVED1
protected static final int FLAG_RESERVED2
protected static final int FLAG_RESERVED3
protected static final int FLAG_RESERVED4
protected static final int FLAG_RESERVED5
protected static final int FLAG_INITIALIZED
protected static final int FLAG_RESERVED8
protected static final int FLAG_REMOVING_FROM_HIERARCHY
public Component(String id)
id
- The non-null id of this componentWicketRuntimeException
- Thrown if the component has been given a null id.public Component(String id, IModel<?> model)
id
- The non-null id of this componentmodel
- The component's modelWicketRuntimeException
- Thrown if the component has been given a null id.public IMarkupFragment getMarkup()
<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.MarkupContainer.getMarkup(Component)
public final String getMarkupIdFromMarkup()
public final void setMarkup(IMarkupFragment markup)
markup
- protected void onConfigure()
Overrides must call super.onConfigure()
, usually before any other code
NOTE: 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()
and
isEnabled()
? 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 by other.isVisible()
as mentioned in
configure()
javadoc.
NOTE: Why should onBeforeRender()
not be used for this? Because if a component's
visibility is controlled inside onBeforeRender()
, once invisible the component will
never become visible again.
protected void onInitialize()
Page
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 method
NOTE:The timing of this call is not precise, the contract is that it is called sometime
before onBeforeRender()
.
public void internalInitialize()
onInitialize()
public final void afterRender()
public final void beforeRender()
configure()
and onBeforeRender()
for this component and all the child
componentspublic final void configure()
onConfigure()
to be invoked on this component if it has not already during
this request.
This method should be invoked before any calls to isVisible()
or
isEnabled()
. 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()); } }
public final void continueToOriginalDestination()
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); } } });
redirectToInterceptPage(Page)
public final void clearOriginalDestination()
public final void debug(Serializable message)
message
- The feedback messagepublic final void detach()
detach
in interface IRequestableComponent
public void detachModels()
public final void error(Serializable message)
message
- The feedback messagepublic final void fatal(Serializable message)
message
- The feedback messagepublic final <Z> Z findParent(Class<Z> c)
Z
- type of parentc
- MarkupContainer class to search forpublic final MarkupContainer findParentWithAssociatedMarkup()
public final Application getApplication()
Application
public final String getClassRelativePath()
getPageRelativePath()
public <C> IConverter<C> getConverter(Class<C> type)
getConverter
in interface IConverterLocator
C
- The object to convert from and to Stringtype
- The type to convert topublic final boolean getEscapeModelStrings()
public String getId()
getId
in interface IRequestableComponent
public final IModel<?> getInnermostModel()
public Locale getLocale()
Session.getLocale()
public final Localizer getLocalizer()
public final ValueMap getMarkupAttributes()
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).
public final Object getMarkupIdImpl()
public String getMarkupId(boolean createIfDoesNotExist)
setMarkupId(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 enable
setOutputMarkupId(boolean)
.
Note: This method should only be called after the component or its parent have been added to the page.
createIfDoesNotExist
- When there is no existing markup id, determines whether it should be generated or
whether null
should be returned.public String getMarkupId()
setMarkupId(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.
public final <M extends Serializable> M getMetaData(MetaDataKey<M> key)
M
- The type of the metadata.key
- The key for the dataMetaDataKey
public final IModel<?> getDefaultModel()
public final Object getDefaultModelObject()
public final String getDefaultModelObjectAsString()
Strings.escapeMarkup(CharSequence, boolean, boolean)
on the model string returned.Strings.escapeMarkup(CharSequence, boolean, boolean)
,
getEscapeModelStrings()
public final String getDefaultModelObjectAsString(Object modelObject)
Strings.escapeMarkup(CharSequence, boolean, boolean)
on the model string returned.modelObject
- Model object to convert to stringStrings.escapeMarkup(CharSequence, boolean, boolean)
,
getEscapeModelStrings()
public final boolean getOutputMarkupId()
getMarkupId()
.public final boolean getOutputMarkupPlaceholderTag()
public final Page getPage()
getPage
in interface IRequestableComponent
WicketRuntimeException
- Thrown if component is not yet attached to a Page.findPage()
public final String getPageRelativePath()
getPageRelativePath
in interface IRequestableComponent
public final MarkupContainer getParent()
getParent
in interface IHierarchical<Component>
public final String getPath()
public final boolean getRenderBodyOnly()
public final Request getRequest()
public final RequestCycle getRequestCycle()
public final Response getResponse()
public Session getSession()
public long getSizeInBytes()
0
- if the size cannot be calculated for some reasonpublic final String getString(String key)
key
- Key of string resource in property fileLocalizer
public final String getString(String key, IModel<?> model)
key
- The resource keymodel
- The modelLocalizer
public final String getString(String key, IModel<?> model, String defaultValue)
key
- The resource keymodel
- The modeldefaultValue
- A default value if the string cannot be foundLocalizer
public final String getStyle()
Session.getStyle()
public String getVariation()
public final boolean hasBeenRendered()
public FeedbackMessages getFeedbackMessages()
FeedbackMessages
instance and add it to the component metadata, even when called on a
component that has no feedback messages, to avoid the overhead use
hasFeedbackMessage()
public final boolean hasErrorMessage()
public final boolean hasFeedbackMessage()
public final void info(Serializable message)
message
- The feedback messagepublic final void success(Serializable message)
message
- The feedback messagepublic final boolean isActionAuthorized(Action action)
action
- The action to authorizeAuthorizationException
- Can be thrown by implementation if action is unauthorizedpublic final boolean isEnableAllowed()
public boolean isEnabled()
public final boolean isRenderAllowed()
RENDER
action is allowed on this
componentRENDER
action is allowed, false otherwisepublic final boolean isStateless()
public boolean isVersioned()
true
if this component should notify its holding page about changes in its
state. If a Page
is not versioned then it wont track changes in its
components and will use the same Page.getPageId()
during its lifetimepublic boolean isVisible()
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)
.
public final boolean isVisibleInHierarchy()
public final void markRendering(boolean setRenderingFlag)
setRenderingFlag
- if this is false only the PREPARED_FOR_RENDER flag is removed from component, the
RENDERING flag is not set.internalPrepareForRender(boolean)
public final void modelChanged()
public final void modelChanging()
public void internalPrepareForRender(boolean setRenderingFlag)
Prepares the component and it's children for rendering. On whole page render this method must be called on the page. On AJAX request, this method must be called on the updated component.
setRenderingFlag
- Whether to set the rendering flag. This must be true if the page is about to be
rendered. However, there are usecases to call this method without an immediate
render (e.g. on stateless listener request target to build the component
hierarchy), in that case setRenderingFlag should be false.public final void prepareForRender()
public final void redirectToInterceptPage(Page page)
page
- The sign in pagecontinueToOriginalDestination()
public final void remove()
You must not use this method in your callback to any of the
MarkupContainer.visitChildren(IVisitor)
methods. See WICKET-3329.
public final void render()
protected void renderPlaceholderTag(ComponentTag tag, Response response)
setOutputMarkupPlaceholderTag(boolean)
has been called with true
.tag
- component tagresponse
- responsepublic final String getAjaxRegionMarkupId()
IAjaxRegionMarkupIdProvider
behavior has been
added.public final void internalRenderComponent()
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.
public final void rendered()
protected final IMarkupSourcingStrategy getMarkupSourcingStrategy()
newMarkupSourcingStrategy()
will be called.protected IMarkupSourcingStrategy newMarkupSourcingStrategy()
getMarkupSourcingStrategy()
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.
public void renderHead(HtmlHeaderContainer container)
NOT intended for overriding by framework clients. Rather, use
renderHead(org.apache.wicket.markup.head.IHeaderResponse)
container
- The HtmlHeaderContainerpublic Component replaceWith(Component replacement)
this.getParent().replace(replacement)
and provides a better context for errors.
Usage: component = component.replaceWith(replacement);
replacement
- component to replace this onepublic final boolean sameInnermostModel(Component component)
component
- The component to compare withpublic final boolean sameInnermostModel(IModel<?> model)
model
- The model to compare withpublic final Component setEnabled(boolean enabled)
enabled
- whether this component is enabledpublic final Component setEscapeModelStrings(boolean escapeMarkup)
escapeMarkup
- True is model strings should be escapedpublic final void setMarkupIdImpl(Object markupId)
markupId
- public Component setMarkupId(String markupId)
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
markupId
- markup id value or null to clear any previous user defined valuegetMarkupId()
public final <M> void setMetaData(MetaDataKey<M> key, M object)
MetaDataKey
.M
- The type of the metadatakey
- The singleton key for the metadataobject
- The metadata objectIllegalArgumentException
MetaDataKey
public Component setDefaultModel(IModel<?> 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.
model
- The modelpublic final Component setDefaultModelObject(Object object)
getDefaultModel().setObject(object)
, this
method checks authorisation and model comparator, and invokes modelChanging
and
modelChanged
if the value really changes.object
- The object to setpublic final Component setOutputMarkupId(boolean output)
getMarkupId()
.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-namepublic final Component setOutputMarkupPlaceholderTag(boolean outputTag)
setOutputMarkupId(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 parameter false
the outputmarkupid flag is not
reverted to false.outputTag
- public final Component setRenderBodyOnly(boolean renderTag)
renderTag
- If true, the component tag will not be printedpublic final <C extends IRequestablePage> void setResponsePage(Class<C> cls)
C
- cls
- The response page classRequestCycle.setResponsePage(Class)
public final <C extends IRequestablePage> void setResponsePage(Class<C> cls, PageParameters parameters)
C
- cls
- The response page classparameters
- The parameters for this bookmarkable page.RequestCycle.setResponsePage(Class, PageParameters)
public final void setResponsePage(Page page)
page
- The response pageRequestCycle.setResponsePage(org.apache.wicket.request.component.IRequestablePage)
public Component setVersioned(boolean versioned)
versioned
- True to turn on versioning for this component, false to turn it off for this
component and any children.public final Component setVisible(boolean visible)
visible
- True if this component and any children should be visiblepublic String toString()
public String toString(boolean detailed)
detailed
- True if a detailed string is desiredpublic final <C extends Page> CharSequence urlFor(Class<C> pageClass, PageParameters parameters)
C
- pageClass
- Class of pageparameters
- Parameters to pageRequestCycle.urlFor(Class, org.apache.wicket.request.mapper.parameter.PageParameters)
public final CharSequence urlFor(Behavior behaviour, RequestListenerInterface listener, PageParameters parameters)
behaviour
- The behavior that the URL should point tolistener
- The listener interface that the URL should callparameters
- The parameters that should be rendered into the urlspublic final CharSequence urlFor(IRequestHandler requestHandler)
requestHandler
- the request target to referenceRequestCycle.urlFor(IRequestHandler)
public final CharSequence urlFor(RequestListenerInterface listener, PageParameters parameters)
listener
- The listener interface that the URL should callparameters
- The parameters that should be rendered into the urlsRequestCycle.urlFor(IRequestHandler)
public final CharSequence urlFor(ResourceReference resourceReference, PageParameters parameters)
resourceReference
- The resource referenceparameters
- parameters or null
if noneRequestCycle.urlFor(IRequestHandler)
public final <R,C extends MarkupContainer> R visitParents(Class<C> parentClass, IVisitor<C,R> visitor)
R
- the type of the result objectparentClass
- Classvisitor
- The visitor to call at each parent of the given typepublic final <R,C extends MarkupContainer> R visitParents(Class<C> parentClass, IVisitor<C,R> visitor, IVisitFilter filter)
R
- the type of the result objectparentClass
- 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
matchespublic final void warn(Serializable message)
message
- The feedback messageprotected final void addStateChange()
protected final void checkComponentTag(ComponentTag tag, String name)
tag
- The tag to checkname
- The expected tag nameMarkupException
- Thrown if the tag is not of the right nameprotected final void checkComponentTagAttribute(ComponentTag tag, String key, String value)
tag
- The tagkey
- The attribute keyvalue
- The required value for the attribute keyMarkupException
- Thrown if the tag does not have the required attribute valueprotected void checkHierarchyChange(Component component)
component
- the component which is about to be added or removedprotected void detachModel()
protected final String exceptionMessage(String message)
message
- The messageprotected final MarkupStream findMarkupStream()
protected final Page findPage()
null
is returned.null
if none can be foundpublic <M extends Behavior> List<M> getBehaviors(Class<M> type)
Behavior
s that are of the provided type as
an unmodifiable list. Returns an empty list if there are no behaviors coupled to this
component.M
- A class derived from Behaviortype
- The type or null for allprotected final boolean getFlag(int flag)
flag
- The flag to testprotected final boolean getRequestFlag(short flag)
flag
- The flag to testprotected final IModel<?> getInnermostModel(IModel<?> model)
model
- The modelpublic IModelComparator getModelComparator()
protected boolean getStatelessHint()
protected IModel<?> initModel()
By default this implementation looks components in the parent chain owning a
IComponentInheritedModel
to provide a model for this component via
IComponentInheritedModel.wrapOnInheritance(Component)
.
For example a FormComponent
has the opportunity to instantiate a model on the fly
using its id
and the containing Form
's model, if the form holds a
CompoundPropertyModel
.
protected void internalOnModelChanged()
Called anytime a model is changed via setModel or setModelObject.
protected boolean isBehaviorAccepted(Behavior behavior)
behavior
- protected final boolean isIgnoreAttributeModifier()
protected void onAfterRender()
protected void onBeforeRender()
NOTE: If you override this, you *must* call super.onBeforeRender() within
your implementation.
Because this method is responsible for cascading onBeforeRender()
call to its
children it is strongly recommended that super call is made at the end of the override.
protected void onComponentTag(ComponentTag tag)
tag
- Tag to modifypublic void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
markupStream
- The markup streamopenTag
- The open tag for the bodyprotected void onDetach()
protected void onRemove()
protected void onModelChanged()
protected void onModelChanging()
protected abstract void onRender()
protected final void renderComponentTag(ComponentTag tag)
tag
- The tag to writeprotected final void replaceComponentTagBody(MarkupStream markupStream, ComponentTag tag, CharSequence body)
markupStream
- The markup stream to replace the tag body intag
- The tagbody
- The new markupprotected final void setAuto(boolean auto)
auto
- True to put component into auto-add modeprotected final void setFlag(int flag, boolean set)
flag
- The flag to setset
- True to turn the flag on, false to turn it offprotected final void setRequestFlag(short flag, boolean set)
flag
- The flag to setset
- True to turn the flag on, false to turn it offprotected final Component setIgnoreAttributeModifier(boolean ignore)
ignore
- If true, all attribute modifiers will be ignoredprotected final <V> IModel<V> wrap(IModel<V> model)
V
- The model typemodel
- The model to wrap if need bepublic Component get(String path)
get
in interface IRequestableComponent
path
- Path to componentpublic final boolean isAuto()
protected void onAfterRenderChildren()
public final void setParent(MarkupContainer parent)
parent
- The parent containerpublic final Component setVisibilityAllowed(boolean allowed)
setVisible(boolean)
will not always have a desired effect because that component may
have isVisible()
overridden. Both setVisibilityAllowed(boolean)
and
isVisibilityAllowed()
are final
so their contract is enforced always.allowed
- this
for chainingpublic final boolean isVisibilityAllowed()
setVisibilityAllowed(boolean)
for details.public final boolean determineVisibility()
isVisible()
, isVisibilityAllowed()
, isRenderAllowed()
true
if the component should be visible, false
otherwisepublic final boolean isEnabledInHierarchy()
isEnabled()
and isEnableAllowed()
both
return true
), and all of its parents are enabled.true
if this component is enabledpublic boolean isRendering()
public boolean canCallListenerInterface(Method method)
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 disabled
webmarkupcontainer 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 if the listener method belongs to IRequestListener
.
method
- listener method about to be invoked on this component. Could be null
- in
this case it means any method.public final void renderHead(Component component, IHeaderResponse response)
IHeaderContributor
. overload
renderHead(org.apache.wicket.markup.head.IHeaderResponse)
instead to
contribute to the response header.component
- response
- public void renderHead(IHeaderResponse response)
renderHead
in interface IHeaderContributor
response
- Response objectpublic void onEvent(IEvent<?> event)
onEvent
in interface IEventSink
public final <T> void send(IEventSink sink, Broadcast type, T payload)
send
in interface IEventSource
T
- type of payloadsink
- 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 payloadpublic Component remove(Behavior... behaviors)
behaviors
- behaviors to removepublic final Behavior getBehaviorById(int id)
getBehaviorById
in interface IRequestableComponent
null
if nonepublic final int getBehaviorId(Behavior behavior)
getBehaviorId
in interface IRequestableComponent
public Component add(Behavior... behaviors)
behaviors
- The behavior modifier(s) to be addedpublic final List<? extends Behavior> getBehaviors()
Behavior
s as a unmodifiable list. Returns an empty list
rather than null if there are no behaviors coupled to this component.protected void onReAdd()
isInitialized()
).
This is similar to onInitialize, but only comes after the component has been removed and
then added again:
Copyright © 2006–2018 Apache Software Foundation. All rights reserved.