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 class
WLink.Builder
This class allows building of WLink in a fluent interface style.static class
WLink.ImagePosition
This is used to control the position of the image on the link.static class
WLink.LinkModel
Holds the extrinsic state information of a WLink.static class
WLink.WindowAttributes
Encapsulates 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 char
getAccessKey()
Action
getAction()
String
getActionCommand()
Retrieves this menu item's action command.Object
getActionObject()
Returns the data object that has been associated with this button, else null.AjaxTarget[]
getActionTargets()
WComponent
getChildAt(int index)
Retrieves a child component by its index.int
getChildCount()
List<WComponent>
getChildren()
Retrieves a list of this Container's.protected WLink.LinkModel
getComponentModel()
Returns the effective component model for this component.Image
getImage()
Return the image to display on the link.WImage
getImageHolder()
WLink.ImagePosition
getImagePosition()
String
getImageUrl()
Return the URL of the image to display on the link.int
getIndexOfChild(WComponent childComponent)
Retrieves the index of the given child.boolean
getOpenNewWindow()
Indicates whether this link should open in a new window.protected WLink.LinkModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.String
getRel()
String
getTargetWindowName()
The name of the target popup window.String
getText()
Return the default text displayed on the link.String
getUrl()
WLink.WindowAttributes
getWindowAttrs()
Retrieves the attributes for new windows which are opened.void
handleRequest(Request request)
Override handleRequest in order to perform processing for this component.boolean
isDisabled()
Indicates whether this link is disabled in the given context.boolean
isRenderAsButton()
Indicates whether this link should render as a button.protected WLink.LinkModel
newComponentModel()
Creates a new model appropriate for this component.protected void
preparePaintComponent(Request request)
Override preparePaintComponent to register an AJAX operation if this link has an action.void
setAccessKey(char accessKey)
Set the access key on the component.void
setAction(Action action, AjaxTarget... actionTargets)
Sets the action that will run if the link is pressed.void
setActionCommand(String actionCommand)
Sets this menu item's action command.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.void
setDisabled(boolean disabled)
Sets whether this link is disabled by default.void
setImage(Image image)
Sets the image to display on the link.void
setImage(String image)
Sets the image to display on the link.void
setImagePosition(WLink.ImagePosition imagePosition)
The position of the image on the link.void
setImageUrl(String imageUrl)
Sets the URL of the image to display on the link.void
setOpenNewWindow(boolean openNewWindow)
Sets whether this link should open in a new window.void
setRel(String rel)
Sets the relationship of the link's target to the current page.void
setRenderAsButton(boolean renderAsButton)
Sets whether this link should render as a button.void
setTargetWindowName(String targetWindowName)
The name of the target popup window.void
setText(String text, Serializable... args)
Sets the text displayed on the link.void
setUrl(String url)
Sets the URL.void
setWindowAttrs(WLink.WindowAttributes windowAttrs)
String
toString()
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, usingMessageFormat
syntax.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:
getAccessKey
in interfaceAccessKeyable
- Returns:
- the component's access key.
-
setAccessKey
public void setAccessKey(char accessKey)
Description copied from interface:AccessKeyable
Set the access key on the component.- Specified by:
setAccessKey
in 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:
isDisabled
in 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:
setDisabled
in 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.WindowAttributes
object 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:
handleRequest
in interfaceWComponent
- Overrides:
handleRequest
in 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:
preparePaintComponent
in 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 theWImage
used by this link to hold theImage
resource.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:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractWComponent
- Returns:
- a String representation of this component, for debugging purposes.
-
getChildCount
public int getChildCount()
- Specified by:
getChildCount
in 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:
getChildAt
in 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:
getIndexOfChild
in 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:
getChildren
in interfaceContainer
- Returns:
- an immutable list of this Container.
-
newComponentModel
protected WLink.LinkModel newComponentModel()
Creates a new model appropriate for this component.- Overrides:
newComponentModel
in 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:
getComponentModel
in 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:
getOrCreateComponentModel
in classWBeanComponent
- Returns:
- the model for this component
-
-