Class WLink
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.WLink
-
- All Implemented Interfaces:
AccessKeyable,AjaxInternalTrigger,AjaxTarget,BeanAware,BeanBound,BeanProviderBound,Container,DataBound,Disableable,SubordinateTarget,WComponent,WebComponent,Serializable
public class WLink extends WBeanComponent implements Container, Disableable, AjaxInternalTrigger, AjaxTarget, SubordinateTarget, AccessKeyable
Note that WLink is different to WButton rendered as a link because WLink will not post the form, and does not support Actions. By default it opens up a new browser window and shows the given url. If the new window attributes needs to be specified then a builder can be usedWLink wLink = new WLink.Builder("WLink using builder and with attrs", "http://bordertech.github.io/"). window("myWcomponentsWindow").width(200).height(200).scrollbars(true).build();Caution must be taken when specifying attributes so that window name is not same for two links on the same page. This can occur when window name is not provided with attributes causing same default window name.- Since:
- 1.0.0
- Author:
- Martin Shevchenko
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWLink.BuilderThis class allows building of WLink in a fluent interface style.static classWLink.ImagePositionThis is used to control the position of the image on the link.static classWLink.LinkModelHolds the extrinsic state information of a WLink.static classWLink.WindowAttributesEncapsulates window attributes for new windows which are opened.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description chargetAccessKey()ActiongetAction()StringgetActionCommand()Retrieves this menu item's action command.ObjectgetActionObject()Returns the data object that has been associated with this button, else null.AjaxTarget[]getActionTargets()WComponentgetChildAt(int index)Retrieves a child component by its index.intgetChildCount()List<WComponent>getChildren()Retrieves a list of this Container's.protected WLink.LinkModelgetComponentModel()Returns the effective component model for this component.ImagegetImage()Return the image to display on the link.WImagegetImageHolder()WLink.ImagePositiongetImagePosition()StringgetImageUrl()Return the URL of the image to display on the link.intgetIndexOfChild(WComponent childComponent)Retrieves the index of the given child.booleangetOpenNewWindow()Indicates whether this link should open in a new window.protected WLink.LinkModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.StringgetRel()StringgetTargetWindowName()The name of the target popup window.StringgetText()Return the default text displayed on the link.StringgetUrl()WLink.WindowAttributesgetWindowAttrs()Retrieves the attributes for new windows which are opened.voidhandleRequest(Request request)Override handleRequest in order to perform processing for this component.booleanisDisabled()Indicates whether this link is disabled in the given context.booleanisRenderAsButton()Indicates whether this link should render as a button.protected WLink.LinkModelnewComponentModel()Creates a new model appropriate for this component.protected voidpreparePaintComponent(Request request)Override preparePaintComponent to register an AJAX operation if this link has an action.voidsetAccessKey(char accessKey)Set the access key on the component.voidsetAction(Action action, AjaxTarget... actionTargets)Sets the action that will run if the link is pressed.voidsetActionCommand(String actionCommand)Sets this menu item's action command.voidsetActionObject(Serializable data)Associate this button with a data object that can be easily accessed in the execute() method of the button's associated Action.voidsetDisabled(boolean disabled)Sets whether this link is disabled by default.voidsetImage(Image image)Sets the image to display on the link.voidsetImage(String image)Sets the image to display on the link.voidsetImagePosition(WLink.ImagePosition imagePosition)The position of the image on the link.voidsetImageUrl(String imageUrl)Sets the URL of the image to display on the link.voidsetOpenNewWindow(boolean openNewWindow)Sets whether this link should open in a new window.voidsetRel(String rel)Sets the relationship of the link's target to the current page.voidsetRenderAsButton(boolean renderAsButton)Sets whether this link should render as a button.voidsetTargetWindowName(String targetWindowName)The name of the target popup window.voidsetText(String text, Serializable... args)Sets the text displayed on the link.voidsetUrl(String url)Sets the URL.voidsetWindowAttrs(WLink.WindowAttributes windowAttrs)StringtoString()Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.AccessKeyable
getAccessKeyAsString
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Method Detail
-
getTargetWindowName
public String getTargetWindowName()
The name of the target popup window. Has no meaning when the link is not a popup.- Returns:
- the target window name.
-
setTargetWindowName
public void setTargetWindowName(String targetWindowName)
The name of the target popup window. Has no meaning when the link is not a popup.- Parameters:
targetWindowName- The targetWindowName to set.
-
getText
public String getText()
Return the default text displayed on the link.- else user text if set
- else shared text if set
- user value if set
- bean value if present
- else shared value
- Returns:
- the link text.
-
setText
public void setText(String text, Serializable... args)
Sets the text displayed on the link.- Parameters:
text- the text to set, usingMessageFormatsyntax.args- optional arguments for the message format string.
-
getUrl
public String getUrl()
- Returns:
- the URL.
-
setUrl
public void setUrl(String url)
Sets the URL.- Parameters:
url- the URL to set.
-
getAccessKey
public char getAccessKey()
- Specified by:
getAccessKeyin interfaceAccessKeyable- Returns:
- the component's access key.
-
setAccessKey
public void setAccessKey(char accessKey)
Description copied from interface:AccessKeyableSet the access key on the component.- Specified by:
setAccessKeyin interfaceAccessKeyable- Parameters:
accessKey- the key that will form a keyboard shortcut to the component.
-
isDisabled
public boolean isDisabled()
Indicates whether this link is disabled in the given context.- Specified by:
isDisabledin interfaceDisableable- Returns:
- true if this link is disabled, otherwise false.
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether this link is disabled by default.- Specified by:
setDisabledin interfaceDisableable- Parameters:
disabled- true if this link is to disabled by default, false for enabled.
-
getRel
public String getRel()
- Returns:
- the relationship of the link's target to the current page.
-
setRel
public void setRel(String rel)
Sets the relationship of the link's target to the current page.- Parameters:
rel- the relationship to set.- See Also:
- Links in html docuemnts
-
getOpenNewWindow
public boolean getOpenNewWindow()
Indicates whether this link should open in a new window.- Returns:
- true if the link should open in a new window, false if it should re-use the existing window.
-
setOpenNewWindow
public void setOpenNewWindow(boolean openNewWindow)
Sets whether this link should open in a new window.- Parameters:
openNewWindow- true to open in a new window, false to re-use the existing window.
-
getWindowAttrs
public WLink.WindowAttributes getWindowAttrs()
Retrieves the attributes for new windows which are opened.To change attributes for individual users, set a new
WLink.WindowAttributesobject for each user.- Returns:
- the attributes for new windows.
-
setWindowAttrs
public void setWindowAttrs(WLink.WindowAttributes windowAttrs)
- Parameters:
windowAttrs- the attributes for new windows which are opened.
-
isRenderAsButton
public boolean isRenderAsButton()
Indicates whether this link should render as a button.- Returns:
- true if this link should render as a button, false for a hyperlink.
-
setRenderAsButton
public void setRenderAsButton(boolean renderAsButton)
Sets whether this link should render as a button.- Parameters:
renderAsButton- true if this link should render as a button, false for a hyperlink.
-
getAction
public Action getAction()
- Returns:
- the action to execute when the link is pressed.
-
setAction
public void setAction(Action action, AjaxTarget... actionTargets)
Sets the action that will run if the link is pressed.The intended use of this action is when the link opens a new window or launches another application such as "mailto".
- Parameters:
action- the action to execute when the link is pressed.actionTargets- the targets to replace when the link is clicked.
-
getActionTargets
public AjaxTarget[] getActionTargets()
- Returns:
- the targets to replace when the link with an action is clicked.
-
getActionCommand
public String getActionCommand()
Retrieves this menu item's action command.- Returns:
- the actionCommand.
-
setActionCommand
public void setActionCommand(String actionCommand)
Sets this menu item's action command.- Parameters:
actionCommand- The actionCommand to set.
-
getActionObject
public Object getActionObject()
Returns the data object that has been associated with this button, else null. For convenience, this data object is passed to the execute() method of the button's associated Action, in the ActionEvent parameter.- Returns:
- the action object.
-
setActionObject
public void setActionObject(Serializable data)
Associate this button with a data object that can be easily accessed in the execute() method of the button's associated Action.- Parameters:
data- the action object.
-
handleRequest
public void handleRequest(Request request)
Override handleRequest in order to perform processing for this component. This implementation checks whether the link has been pressed via the current ajax operation.- Specified by:
handleRequestin interfaceWComponent- Overrides:
handleRequestin classAbstractWComponent- Parameters:
request- the request being responded to.
-
preparePaintComponent
protected void preparePaintComponent(Request request)
Override preparePaintComponent to register an AJAX operation if this link has an action.- Overrides:
preparePaintComponentin classAbstractWComponent- Parameters:
request- the request being responded to.
-
getImage
public Image getImage()
Return the image to display on the link.- Returns:
- the image.
-
setImage
public void setImage(Image image)
Sets the image to display on the link.- Parameters:
image- the image, or null for no image.
-
setImage
public void setImage(String image)
Sets the image to display on the link. The image will be read from the application's class path rather than from its web docs.- Parameters:
image- the relative path to the image resource, or null for no image.
-
getImageHolder
public WImage getImageHolder()
Return theWImageused by this link to hold theImageresource.If the link is not using an Image resource, it will return null.
- Returns:
- the WImage holding the Image resource, or null if the link is not using an Image resource.
-
getImageUrl
public String getImageUrl()
Return the URL of the image to display on the link.- Returns:
- the image url.
-
setImageUrl
public void setImageUrl(String imageUrl)
Sets the URL of the image to display on the link.- Parameters:
imageUrl- the image url, or null for no image.
-
getImagePosition
public WLink.ImagePosition getImagePosition()
- Returns:
- the position of the image
-
setImagePosition
public void setImagePosition(WLink.ImagePosition imagePosition)
The position of the image on the link.- Parameters:
imagePosition- the position of the image
-
toString
public String toString()
Description copied from class:AbstractWComponentCreates a String representation of this component; usually for debugging purposes.- Overrides:
toStringin classAbstractWComponent- Returns:
- a String representation of this component, for debugging purposes.
-
getChildCount
public int getChildCount()
- Specified by:
getChildCountin interfaceContainer- Returns:
- the number of child components currently contained within this component.
-
getChildAt
public WComponent getChildAt(int index)
Retrieves a child component by its index.- Specified by:
getChildAtin interfaceContainer- Parameters:
index- the index of the child component to be retrieved.- Returns:
- the child component at the given index.
-
getIndexOfChild
public int getIndexOfChild(WComponent childComponent)
Retrieves the index of the given child.- Specified by:
getIndexOfChildin interfaceContainer- Parameters:
childComponent- the child component to retrieve the index for.- Returns:
- the index of the given child component, or -1 if the component is not a child of this component.
-
getChildren
public List<WComponent> getChildren()
Retrieves a list of this Container's.- Specified by:
getChildrenin interfaceContainer- Returns:
- an immutable list of this Container.
-
newComponentModel
protected WLink.LinkModel newComponentModel()
Creates a new model appropriate for this component.- Overrides:
newComponentModelin classWBeanComponent- Returns:
- a new
WLink.LinkModel.
-
getComponentModel
protected WLink.LinkModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModelin classWBeanComponent- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WLink.LinkModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModelin classWBeanComponent- Returns:
- the model for this component
-
-