Class AbstractLink
- java.lang.Object
-
- org.openidentityplatform.openam.click.control.AbstractControl
-
- org.openidentityplatform.openam.click.control.AbstractLink
-
- All Implemented Interfaces:
Serializable,org.apache.click.Stateful,org.openidentityplatform.openam.click.Control
- Direct Known Subclasses:
ActionLink
public abstract class AbstractLink extends AbstractControl implements org.apache.click.Stateful
Provides a Abstract Link control: <a href=""></a>.See also the W3C HTML reference: A Links
- See Also:
ActionLink,Submit, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandisabledThe Field disabled value.protected StringimageSrcThe image src path attribute.protected StringlabelThe link display label.protected Map<String,Object>parametersThe link parameters map.protected booleanrenderLabelAndImageFlag to set if both icon and text are rendered, default value is false.protected inttabindexThe link 'tabindex' attribute.protected StringtitleThe link title attribute, which acts as a tooltip help message.-
Fields inherited from class org.openidentityplatform.openam.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
-
-
Constructor Summary
Constructors Constructor Description AbstractLink()Create an AbstractLink with no name defined.AbstractLink(String name)Create an AbstractLink for the given name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidbindRequestParameters(org.openidentityplatform.openam.click.Context context)This method binds the submitted request parameters to the link parameters.voidbindRequestValue()This method does nothing by default since AbstractLink does not bind to request values.voiddefineParameter(String name)Defines a link parameter that will have its value bound to a matching request parameter.abstract StringgetHref()Return the AbstractLink anchor <a> tag href attribute.StringgetId()Return the "id" attribute value if defined, or null otherwise.StringgetImageSrc()Return the image src path attribute.StringgetLabel()Return the label for the AbstractLink.StringgetParameter(String name)Return the link request parameter value for the given name, or null if the parameter value does not exist.Map<String,Object>getParameters()Return the AbstractLink parameters Map.String[]getParameterValues(String name)Return the link request parameter values for the given name, or null if the parameter values does not exist.ObjectgetState()Return the link state.intgetTabIndex()Return the link "tabindex" attribute value.StringgetTag()Return the link html tag:a.StringgetTitle()Return the 'title' attribute, or null if not defined.booleanhasParameters()Return true if the AbstractLink has parameters, false otherwise.booleanisAjaxTarget(org.openidentityplatform.openam.click.Context context)Returnstrueif this control is an AJAX target,falseotherwise.booleanisDisabled()Return true if the AbstractLink is a disabled.booleanisRenderLabelAndImage()voidremoveState(org.openidentityplatform.openam.click.Context context)Remove the link state from the session for the given request context.voidrender(HtmlStringBuffer buffer)Render the HTML representation of the anchor link.protected voidrenderImgTag(HtmlStringBuffer buffer)Render the Image tag to the buffer.protected voidrenderParameters(HtmlStringBuffer buffer, Map<String,Object> parameters, org.openidentityplatform.openam.click.Context context)Render the given link parameters to the buffer.voidrestoreState(org.openidentityplatform.openam.click.Context context)Restore the link state from the session for the given request context.voidsaveState(org.openidentityplatform.openam.click.Context context)Save the link state to the session for the given request context.voidsetDisabled(boolean disabled)Set the disabled flag.voidsetImageSrc(String src)Set the image src path attribute.voidsetLabel(String label)Set the label for the ActionLink.voidsetParameter(String name, Object value)Set the link parameter with the given parameter name and value.voidsetParameters(Map parameters)Set the AbstractLink parameter map.voidsetParameterValues(String name, Object[] values)Set the link parameter with the given parameter name and values.voidsetRenderLabelAndImage(boolean renderLabelAndImage)voidsetState(Object state)Set the link state.voidsetTabIndex(int tabindex)Set the link "tabindex" attribute value.voidsetTitle(String value)Set the 'title' attribute tooltip message.-
Methods inherited from class org.openidentityplatform.openam.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, onDeploy, onDestroy, onInit, onProcess, onRender, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setName, setParent, setStyle, toString
-
-
-
-
Field Detail
-
disabled
protected boolean disabled
The Field disabled value.
-
imageSrc
protected String imageSrc
The image src path attribute. If the image src is defined then a<img/>element will rendered inside the anchor link when using the AbstractLinkAbstractControl.toString()method.If the image src value is prefixed with '/' then the request context path will be prefixed to the src value when rendered by the control.
-
label
protected String label
The link display label.
-
tabindex
protected int tabindex
The link 'tabindex' attribute.
-
title
protected String title
The link title attribute, which acts as a tooltip help message.
-
renderLabelAndImage
protected boolean renderLabelAndImage
Flag to set if both icon and text are rendered, default value is false.
-
-
Constructor Detail
-
AbstractLink
public AbstractLink(String name)
Create an AbstractLink for the given name.- Parameters:
name- the page link name- Throws:
IllegalArgumentException- if the name is null
-
AbstractLink
public AbstractLink()
Create an AbstractLink with no name defined.Please note the control's name must be defined before it is valid.
-
-
Method Detail
-
getTag
public String getTag()
Return the link html tag:a.- Overrides:
getTagin classAbstractControl- Returns:
- this controls html tag
- See Also:
AbstractControl.getTag()
-
isDisabled
public boolean isDisabled()
Return true if the AbstractLink is a disabled. If the link is disabled it will be rendered as <span> element with a HTML class attribute of "disabled".- Returns:
- true if the AbstractLink is a disabled
-
setDisabled
public void setDisabled(boolean disabled)
Set the disabled flag. If the link is disabled it will be rendered as <span> element with a HTML class attribute of "disabled".- Parameters:
disabled- the disabled flag
-
getHref
public abstract String getHref()
Return the AbstractLink anchor <a> tag href attribute. This method will encode the URL with the session ID if required usingHttpServletResponse.encodeURL().- Returns:
- the AbstractLink HTML href attribute
-
getImageSrc
public String getImageSrc()
Return the image src path attribute. If the image src is defined then a<img/>element will be rendered inside the anchor link when using the AbstractLinkAbstractControl.toString()method.Note: the label will not be rendered in this case (default behavior), unless the
setRenderLabelAndImage(boolean)flag is set to true.If the src value is prefixed with '/' then the request context path will be prefixed to the src value when rendered by the control.
- Returns:
- the image src path attribute
-
setImageSrc
public void setImageSrc(String src)
Set the image src path attribute. If the src value is prefixed with '/' then the request context path will be prefixed to the src value when rendered by the control.If the image src is defined then an
<img/>element will be rendered inside the anchor link when using the AbstractLinkAbstractControl.toString()method.Note: the label will not be rendered in this case (default behavior), unless the
setRenderLabelAndImage(boolean)flag is set to true.- Parameters:
src- the image src path attribute
-
getId
public String getId()
Return the "id" attribute value if defined, or null otherwise.- Specified by:
getIdin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
getIdin classAbstractControl- Returns:
- HTML element identifier attribute "id" value
- See Also:
Control.getId()
-
getLabel
public String getLabel()
Return the label for the AbstractLink.If the label value is null, this method will attempt to find a localized label message in the parent messages using the key:
If not found then the message will be looked up in thegetName() + ".label"/click-control.propertiesfile using the same key. If a value still cannot be found then the ActionLink name will be converted into a label using the method:ClickUtils.toLabel(String)For example given a
OrderPagewith the properties fileOrderPage.properties:checkout.label=Checkout checkout.title=Proceed to Checkout
The page ActionLink code:public class OrderPage extends Page { ActionLink checkoutLink = new ActionLink("checkout"); .. }
Will render the AbstractLink label and title properties as:<a href=".." title="Proceed to Checkout">Checkout</a>
When a label value is not set, or defined in any properties files, then its value will be created from the Fields name.For example given the ActionLink code:
ActionLink nameField = new ActionLink("deleteItem");
Will render the ActionLink label as:<a href="..">Delete Item</a>Note the ActionLink label can include raw HTML to render other elements.For example the configured label:
edit.label=<img src="images/edit.png" title="Edit Item"/>
Will render the ActionLink label as:<a href=".."><img src="images/edit.png" title="Edit Item"/></a>- Returns:
- the label for the ActionLink
-
setLabel
public void setLabel(String label)
Set the label for the ActionLink.- Parameters:
label- the label for the ActionLink- See Also:
getLabel()
-
getParameter
public String getParameter(String name)
Return the link request parameter value for the given name, or null if the parameter value does not exist.- Parameters:
name- the name of request parameter- Returns:
- the link request parameter value
-
setParameter
public void setParameter(String name, Object value)
Set the link parameter with the given parameter name and value. You would generally use parameter if you were creating the entire AbstractLink programmatically and rendering it with theAbstractControl.toString()method.For example given the ActionLink:
PageLink editLink = new PageLink("editLink", EditCustomer.class); editLink.setLabel("Edit Customer"); editLink.setParameter("customerId", customerId);
And the page template:$editLinkWill render the HTML as:<a href="/mycorp/edit-customer.htm?customerId=13490">Edit Customer</a>
- Parameters:
name- the attribute namevalue- the attribute value- Throws:
IllegalArgumentException- if name parameter is null
-
getParameterValues
public String[] getParameterValues(String name)
Return the link request parameter values for the given name, or null if the parameter values does not exist.- Parameters:
name- the name of request parameter- Returns:
- the link request parameter values
-
setParameterValues
public void setParameterValues(String name, Object[] values)
Set the link parameter with the given parameter name and values. If the values are null, the parameter will be removed from theparameters.- Parameters:
name- the attribute namevalues- the attribute values- Throws:
IllegalArgumentException- if name parameter is null- See Also:
setParameter(String, Object)
-
getParameters
public Map<String,Object> getParameters()
Return the AbstractLink parameters Map.- Returns:
- the AbstractLink parameters Map
-
setParameters
public void setParameters(Map parameters)
Set the AbstractLink parameter map.- Parameters:
parameters- the link parameter map
-
defineParameter
public void defineParameter(String name)
Defines a link parameter that will have its value bound to a matching request parameter.setParameterimplicitly defines a parameter as well.Please note: parameters need only be defined for Ajax requests. For non-Ajax requests,
allincoming request parameters are bound, whether they are defined or not. This behavior may change in a future release.Also note: link parameters are bound to request parameters during the
AbstractControl.onProcess()event, so link parameters must be defined in the Page constructor oronInit()event.- Parameters:
name- the name of the parameter to define
-
hasParameters
public boolean hasParameters()
Return true if the AbstractLink has parameters, false otherwise.- Returns:
- true if the AbstractLink has parameters, false otherwise
-
getTabIndex
public int getTabIndex()
Return the link "tabindex" attribute value.- Returns:
- the link "tabindex" attribute value
-
setTabIndex
public void setTabIndex(int tabindex)
Set the link "tabindex" attribute value.- Parameters:
tabindex- the link "tabindex" attribute value
-
getTitle
public String getTitle()
Return the 'title' attribute, or null if not defined. The title attribute acts like tooltip message over the link.If the title value is null, this method will attempt to find a localized label message in the parent messages using the key:
If not found then the message will be looked up in thegetName() + ".title"/click-control.propertiesfile using the same key.For examle given a
ItemsPagewith the properties fileItemPage.properties:edit.label=Edit edit.title=Edit Item
The page ActionLink code:public class ItemsPage extends Page { ActionLink editLink = new ActionLink("edit"); .. }
Will render the ActionLink label and title properties as:<a href=".." title="Edit Item">Edit</a>
- Returns:
- the 'title' attribute tooltip message
-
setTitle
public void setTitle(String value)
Set the 'title' attribute tooltip message.- Parameters:
value- the 'title' attribute tooltip message- See Also:
getTitle()
-
isRenderLabelAndImage
public boolean isRenderLabelAndImage()
- Returns:
trueif both icon and text are rendered,falseotherwise
-
setRenderLabelAndImage
public void setRenderLabelAndImage(boolean renderLabelAndImage)
- Parameters:
renderLabelAndImage- sets the rendering type of the link.
-
isAjaxTarget
public boolean isAjaxTarget(org.openidentityplatform.openam.click.Context context)
Description copied from class:AbstractControlReturnstrueif this control is an AJAX target,falseotherwise.The control is defined as an Ajax target if the control
IDis send as a request parameter.- Specified by:
isAjaxTargetin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
isAjaxTargetin classAbstractControl- Parameters:
context- the request context- Returns:
trueif this control is an AJAX target,falseotherwise
-
bindRequestValue
public void bindRequestValue()
This method does nothing by default since AbstractLink does not bind to request values.
-
getState
public Object getState()
Return the link state. The following state is returned:- Specified by:
getStatein interfaceorg.apache.click.Stateful- Returns:
- the link state
-
setState
public void setState(Object state)
Set the link state.- Specified by:
setStatein interfaceorg.apache.click.Stateful- Parameters:
state- the link state to set
-
render
public void render(HtmlStringBuffer buffer)
Render the HTML representation of the anchor link. This method will render the entire anchor link including the tags, the label and any attributes, seeAbstractControl.setAttribute(String, String)for an example.If the image src is defined then a
<img/>element will rendered inside the anchor link instead of the label property.This method invokes the abstract
getHref()method.- Specified by:
renderin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
renderin classAbstractControl- Parameters:
buffer- the specified buffer to render the control's output to- See Also:
AbstractControl.toString()
-
removeState
public void removeState(org.openidentityplatform.openam.click.Context context)
Remove the link state from the session for the given request context.- Parameters:
context- the request context- See Also:
saveState(Context),restoreState(Context)
-
restoreState
public void restoreState(org.openidentityplatform.openam.click.Context context)
Restore the link state from the session for the given request context.This method delegates to
setState(Object)to set the link restored state.- Parameters:
context- the request context- See Also:
saveState(Context),removeState(Context)
-
saveState
public void saveState(org.openidentityplatform.openam.click.Context context)
Save the link state to the session for the given request context.* This method delegates to
getState()to retrieve the link state to save.- Parameters:
context- the request context- See Also:
restoreState(Context),removeState(Context)
-
renderImgTag
protected void renderImgTag(HtmlStringBuffer buffer)
Render the Image tag to the buffer.- Parameters:
buffer- the buffer to render the image tag to
-
renderParameters
protected void renderParameters(HtmlStringBuffer buffer, Map<String,Object> parameters, org.openidentityplatform.openam.click.Context context)
Render the given link parameters to the buffer.The parameters will be rendered as URL key/value pairs e.g: "
firstname=john&lastname=smith".Multivalued parameters will be rendered with each value sharing the same key e.g: "
name=john&name=susan&name=mary".The parameter value will be encoded through
ClickUtils.encodeUrl(Object, Context).- Parameters:
buffer- the buffer to render the parameters toparameters- the parameters to rendercontext- the request context
-
bindRequestParameters
protected void bindRequestParameters(org.openidentityplatform.openam.click.Context context)
This method binds the submitted request parameters to the link parameters.For non-Ajax requests this method will bind
allincoming request parameters to the link. For Ajax requests this method will only bind the parameters already defined on the link.- Parameters:
context- the request context
-
-