wicket.markup.html.link
Class Link

java.lang.Object
  extended by wicket.Component
      extended by wicket.MarkupContainer
          extended by wicket.markup.html.WebMarkupContainer
              extended by wicket.markup.html.link.Link
All Implemented Interfaces:
java.io.Serializable, IRequestListener, ILinkListener
Direct Known Subclasses:
AjaxFallbackLink, BookmarkablePageLink, DownloadLink, DummyHomePage.TestLink, PageLink, PagingNavigationIncrementLink, PagingNavigationLink, PopupCloseLink, ResourceLink

public abstract class Link
extends WebMarkupContainer
implements ILinkListener

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, an onclick javascript event handler attribute will be generated.

You can use a link like:

                      add(new Link("myLink")
                      {
                          public void onClick(RequestCycle cycle)
                          {
                              // 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("link", listItem.getModel()) 
                      {
                          public void onClick() 
                          {
                              MyObject obj = (MyObject)getModelObject();
                              setResponsePage(new MyPage(obj.getId(), ... ));
                          }
 

Author:
Jonathan Locke, Eelco Hillenius
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor, Component.VisibilityChange
 
Field Summary
 
Fields inherited from class wicket.Component
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Fields inherited from interface wicket.markup.html.link.ILinkListener
INTERFACE
 
Constructor Summary
Link(java.lang.String id)
           
Link(java.lang.String id, IModel object)
           
 
Method Summary
protected  java.lang.CharSequence appendAnchor(ComponentTag tag, java.lang.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).
 java.lang.String getAfterDisabledLink()
          Gets the insertion string to allow disabled links to look like Disabled link .
 Component getAnchor()
          Gets any anchor component.
 boolean getAutoEnable()
          Gets whether link should automatically enable/disable based on current page.
 java.lang.String getBeforeDisabledLink()
          Gets the insertion string to allow disabled links to look like Disabled link .
protected  java.lang.CharSequence getOnClickScript(java.lang.CharSequence url)
           
protected  java.lang.String getOnClickScript(java.lang.String url)
          Deprecated. this method will be removed by getOnClickScript(CharSequence) shortly. Please override that method instead.
 PopupSettings getPopupSettings()
          Gets the popup specification.
protected  java.lang.CharSequence getURL()
          Gets the url to use for this link.
protected  void internalOnAttach()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 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.
protected  void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
          Renders this link's body.
 void onLinkClicked()
          THIS METHOD IS NOT PART OF THE WICKET API.
 void setAfterDisabledLink(java.lang.String afterDisabledLink)
          Sets the insertion string to allow disabled links to look like Disabled link .
 void setAnchor(Component anchor)
          Sets an anchor component.
 Link setAutoEnable(boolean autoEnable)
          Sets whether this link should automatically enable/disable based on current page.
 void setBeforeDisabledLink(java.lang.String beforeDisabledLink)
          Sets the insertion string to allow disabled links to look like Disabled link .
 Link setPopupSettings(PopupSettings popupSettings)
          Sets the popup specification.
 
Methods inherited from class wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage
 
Methods inherited from class wicket.MarkupContainer
add, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, internalAdd, internalAttach, internalDetach, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren
 
Methods inherited from class wicket.Component
add, addStateChange, checkComponentTag, checkComponentTagAttribute, continueToOriginalDestination, debug, detachBehaviors, detachModel, detachModels, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getApplicationPages, getApplicationSettings, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getOutputMarkupId, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isBehaviorAccepted, isEnableAllowed, isHeadRendered, isIgnoreAttributeModifier, isRenderAllowed, isVersioned, isVisible, isVisibleInHierarchy, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeforeRender, onBeginRequest, onDetach, onEndRequest, onModelChanged, onModelChanging, onRender, redirectToInterceptPage, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderedBehaviors, renderHead, replaceComponentTagBody, replaceWith, resetHeadRendered, sameRootModel, sameRootModel, setAuto, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMetaData, setModelObject, setOutputMarkupId, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Link

public Link(java.lang.String id)
See Also:
Component.Component(String)

Link

public Link(java.lang.String id,
            IModel object)
See Also:
Component.Component(String, IModel)
Method Detail

getAfterDisabledLink

public java.lang.String getAfterDisabledLink()
Gets the insertion string to allow disabled links to look like Disabled link .

Returns:
The insertion string

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.

getBeforeDisabledLink

public java.lang.String getBeforeDisabledLink()
Gets the insertion string to allow disabled links to look like Disabled link .

Returns:
The insertion string

getPopupSettings

public 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 class Component
Returns:
Whether this component is enabled.
See Also:
Component.isEnabled()

onClick

public abstract void onClick()
Called when a link is clicked.


onLinkClicked

public final void onLinkClicked()
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:
onLinkClicked in interface ILinkListener
See Also:
ILinkListener

setAfterDisabledLink

public void setAfterDisabledLink(java.lang.String afterDisabledLink)
Sets the insertion string to allow disabled links to look like Disabled link .

Parameters:
afterDisabledLink - The insertion string

setAnchor

public void 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 the Component.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

setAutoEnable

public final Link 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

setBeforeDisabledLink

public void setBeforeDisabledLink(java.lang.String beforeDisabledLink)
Sets the insertion string to allow disabled links to look like Disabled link .

Parameters:
beforeDisabledLink - The insertion string

setPopupSettings

public final Link 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 java.lang.CharSequence appendAnchor(ComponentTag tag,
                                              java.lang.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 calling Component.getMarkupId() if Component.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, an excpeption 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 tag
url - The url to start with
Returns:
The url, possibly with an anchor appended

getOnClickScript

protected java.lang.CharSequence getOnClickScript(java.lang.CharSequence url)
Parameters:
url - The url for the link
Returns:
Any onClick JavaScript that should be used

getOnClickScript

protected java.lang.String getOnClickScript(java.lang.String url)
Deprecated. this method will be removed by getOnClickScript(CharSequence) shortly. Please override that method instead.

Parameters:
url - The url for the link
Returns:
Any onClick JavaScript that should be used

getURL

protected java.lang.CharSequence getURL()
Gets the url to use for this link.

Returns:
The URL that this link links to

internalOnAttach

protected void internalOnAttach()
Description copied from class: Component
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL OR OVERRIDE. Called when a request begins.

Overrides:
internalOnAttach in class Component
See Also:
Component.internalOnAttach()

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 final void onComponentTag(ComponentTag tag)
Handles this link's tag.

Overrides:
onComponentTag in class Component
Parameters:
tag - the component tag
See Also:
Component.onComponentTag(ComponentTag)

onComponentTagBody

protected final void onComponentTagBody(MarkupStream markupStream,
                                        ComponentTag openTag)
Renders this link's body.

Overrides:
onComponentTagBody in class MarkupContainer
Parameters:
markupStream - the markup stream
openTag - the open part of this tag
See Also:
Component.onComponentTagBody(MarkupStream, ComponentTag)


Copyright © 2004-2007 Wicket developers. All Rights Reserved.