Class Link<T>
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.link.AbstractLink
-
- org.apache.wicket.markup.html.link.Link<T>
-
- Type Parameters:
T
- type of model object
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IGenericComponent<T,Link<T>>
,IMetadataContext<Serializable,Component>
,IRequestListener
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
AjaxFallbackLink
,BookmarkablePageLink
,BreadCrumbLink
,DownloadLink
,DummyHomePage.TestLink
,OrderByLink
,PagingNavigationIncrementLink
,PagingNavigationLink
,PopupCloseLink
,ResourceLink
,StatelessLink
public abstract class Link<T> extends AbstractLink implements IRequestListener, IGenericComponent<T,Link<T>>
Implementation of a hyperlink component. A link can be used with an anchor (<a href...) element or any element that supports the onclick javascript event handler (such as buttons, td elements, etc). When used with an anchor, a href attribute will be generated. When used with any other element, a click javascript event handler will be added.You can use a link like:
add(new Link("myLink") { public void onClick() { // do something here... } );
and in your HTML file:<a href="#" wicket:id="myLink">click here</a>
or:<td wicket:id="myLink">my clickable column</td>
The following snippet shows how to pass a parameter from the Page creating the Page to the Page responded by the Link.
add(new Link<MyObject>("link", listItem.getModel()) { public void onClick() { MyObject obj = getModelObject(); setResponsePage(new MyPage(obj)); }
- Author:
- Jonathan Locke, Eelco Hillenius
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected CharSequence
appendAnchor(ComponentTag tag, CharSequence url)
Appends any anchor to the url if the url is not null and the url does not already contain an anchor (url.indexOf('#') != -1).Component
getAnchor()
Gets any anchor component.boolean
getAutoEnable()
Gets whether link should automatically enable/disable based on current page.protected CharSequence
getOnClickScript(CharSequence url)
PopupSettings
getPopupSettings()
Gets the popup specification.protected boolean
getStatelessHint()
Returns whether the component can be stateless.protected CharSequence
getURL()
Gets the url to use for this link.boolean
isEnabled()
Gets whether this component is enabled.protected boolean
linksTo(Page page)
Whether this link refers to the given page.abstract void
onClick()
Called when a link is clicked.protected void
onComponentTag(ComponentTag tag)
Handles this link's tag.void
onRequest()
THIS METHOD IS NOT PART OF THE WICKET API.void
renderHead(IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.Link<T>
setAnchor(Component anchor)
Sets an anchor component.Link<T>
setAutoEnable(boolean autoEnable)
Sets whether this link should automatically enable/disable based on current page.Link<T>
setPopupSettings(PopupSettings popupSettings)
Sets the popup specification.protected boolean
useJSEventBindingWhenNeeded()
This method can be overridden by a subclass to disable the JS event binding or provide custom event binding code is used.-
Methods inherited from class org.apache.wicket.markup.html.link.AbstractLink
disableLink, getBody, onComponentTagBody, onDetach, setBody
-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IGenericComponent
getDefaultModel, getDefaultModelObject, getModel, getModelObject, setDefaultModel, setDefaultModelObject, setModel, setModelObject
-
Methods inherited from interface org.apache.wicket.IRequestListener
rendersPage
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
Link
public Link(String id)
- See Also:
Component(String)
-
Link
public Link(String id, IModel<T> model)
- Parameters:
id
-model
-- See Also:
Component(String, IModel)
-
-
Method Detail
-
getAnchor
public Component getAnchor()
Gets any anchor component.- Returns:
- Any anchor component to jump to, might be null
-
getAutoEnable
public final boolean getAutoEnable()
Gets whether link should automatically enable/disable based on current page.- Returns:
- Whether this link should automatically enable/disable based on current page.
-
getPopupSettings
public final PopupSettings getPopupSettings()
Gets the popup specification. If not-null, a javascript on-click event handler will be generated that opens a new window using the popup properties.- Returns:
- the popup specification.
-
isEnabled
public boolean isEnabled()
Description copied from class:Component
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.- Overrides:
isEnabled
in classComponent
- Returns:
- Whether this component is enabled.
- See Also:
Component.isEnabled()
-
getStatelessHint
protected boolean getStatelessHint()
Description copied from class:Component
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.- Overrides:
getStatelessHint
in classComponent
- Returns:
- whether the component can be stateless
- See Also:
Component.getStatelessHint()
-
onClick
public abstract void onClick()
Called when a link is clicked.
-
onRequest
public void onRequest()
THIS METHOD IS NOT PART OF THE WICKET API. DO NOT ATTEMPT TO OVERRIDE OR CALL IT. Called when a link is clicked. The implementation of this method is currently to simply call onClick(), but this may be augmented in the future.- Specified by:
onRequest
in interfaceIRequestListener
-
setAnchor
public Link<T> setAnchor(Component anchor)
Sets an anchor component. An anchor (form 'http://server/app/etc#someAnchor') will be appended to the link so that after this link executes, it will jump to the provided anchor component's position. The provided anchor must either have theComponent.getOutputMarkupId()
flag true, or it must be attached to a <a tag with a href attribute of more than one character starting with '#' ('<a href="#someAnchor" ... ').- Parameters:
anchor
- The anchor- Returns:
- this
-
setAutoEnable
public final Link<T> setAutoEnable(boolean autoEnable)
Sets whether this link should automatically enable/disable based on current page.- Parameters:
autoEnable
- whether this link should automatically enable/disable based on current page.- Returns:
- This
-
setPopupSettings
public final Link<T> setPopupSettings(PopupSettings popupSettings)
Sets the popup specification. If not-null, a javascript on-click event handler will be generated that opens a new window using the popup properties.- Parameters:
popupSettings
- the popup specification.- Returns:
- This
-
appendAnchor
protected CharSequence appendAnchor(ComponentTag tag, CharSequence url)
Appends any anchor to the url if the url is not null and the url does not already contain an anchor (url.indexOf('#') != -1). This implementation looks whether an anchor component was set, and if so, it will append the markup id of that component. That markup id is gotten by either callingComponent.getMarkupId()
ifComponent.getOutputMarkupId()
returns true, or if the anchor component does not output it's id, this method will try to retrieve the id from the markup directly. If neither is found, anexception
is thrown. If no anchor component was set, but the link component is attached to a <a element, this method will append what is in the href attribute if there is one, starts with a '#' and has more than one character.You can override this method, but it means that you have to take care of whatever is done with any set anchor component yourself. You also have to manually append the '#' at the right place.
- Parameters:
tag
- The component tagurl
- The url to start with- Returns:
- The url, possibly with an anchor appended
-
getOnClickScript
protected CharSequence getOnClickScript(CharSequence url)
- Parameters:
url
- The url for the link- Returns:
- Any onClick JavaScript that should be used
-
getURL
protected CharSequence getURL()
Gets the url to use for this link.- Returns:
- The URL that this link links to
-
linksTo
protected boolean linksTo(Page page)
Whether this link refers to the given page.- Parameters:
page
- A page- Returns:
- True if this link goes to the given page
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Handles this link's tag. OVERRIDES MUST CALL SUPER.- Overrides:
onComponentTag
in classComponent
- Parameters:
tag
- the component tag- See Also:
Component.onComponentTag(ComponentTag)
-
renderHead
public void renderHead(IHeaderResponse response)
Description copied from class:Component
Render to the web response whatever the component wants to contribute to the head section.- Specified by:
renderHead
in interfaceIHeaderContributor
- Overrides:
renderHead
in classComponent
- Parameters:
response
- Response object
-
useJSEventBindingWhenNeeded
protected boolean useJSEventBindingWhenNeeded()
This method can be overridden by a subclass to disable the JS event binding or provide custom event binding code is used.- Returns:
- true when a javascripot event binding must used to handle the click event.
-
-