Class ActionLink
- java.lang.Object
-
- org.openidentityplatform.openam.click.control.AbstractControl
-
- org.openidentityplatform.openam.click.control.AbstractLink
-
- org.openidentityplatform.openam.click.control.ActionLink
-
- All Implemented Interfaces:
Serializable,org.apache.click.Stateful,org.openidentityplatform.openam.click.Control
public class ActionLink extends AbstractLink
Provides a Action Link control: <a href=""></a>.
This control can render the "href" URL attribute usingExample Action Link getHref(), or the entire ActionLink anchor tag usingAbstractControl.toString().ActionLink support invoking control listeners.
ActionLink Example
An example of using ActionLink to call a logout method is illustrated below:public class MyPage extends Page { public MyPage() { ActionLink link = new ActionLink("logoutLink"); link.setListener(this, "onLogoutClick"); addControl(link); } public boolean onLogoutClick() { if (getContext().hasSession()) { getContext().getSession().invalidate(); } setRedirect(LogoutPage.class); return false; } }
The corresponding template code is below. Note href is evaluated by Velocity togetHref():<a href="$logoutLink.href" title="Click to Logout">Logout</a>ActionLink can also support a value parameter which is accessible usinggetValue().For example a products table could include rows of products, each with a get product details ActionLink and add product ActionLink. The ActionLinks include the product's id as a parameter to the
getHref(Object)method, which is then available when the control is processed:<table> #foreach ($product in $productList) <tr> <td> $product.name </td> <td> <a href="$detailsLink.getHref($product.id)" title="Get product information">Details</a> </td> <td> <a href="$addLink.getHref($product.id)" title="Add to basket">Add</a> </td> </tr> #end </table>
The corresponding Page class for this template is:public class ProductsPage extends Page { public ActionLink addLink = new ActionLink("addLink", this, "onAddClick"); public ActionLink detailsLink = new ActionLink("detailsLink", this, "onDetailsClick"); public List productList; public boolean onAddClick() { // Get the product clicked on by the user Integer productId = addLink.getValueInteger(); Product product = getProductService().getProduct(productId); // Add product to basket List basket = (List) getContext().getSessionAttribute("basket"); basket.add(product); getContext().setSessionAttribute("basket", basket); return true; } public boolean onDetailsClick() { // Get the product clicked on by the user Integer productId = detailsLink.getValueInteger(); Product product = getProductService().getProduct(productId); // Store the product in the request and display in the details page getContext().setRequestAttribute("product", product); setForward(ProductDetailsPage.class); return false; } public void onRender() { // Display the list of available products productList = getProductService().getProducts(); } }
See also the W3C HTML reference: A Links- See Also:
AbstractLink,Submit, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringACTION_LINKThe action link parameter name:actionLink.protected booleanclickedThe link is clicked.static StringVALUEThe value parameter name:value.-
Fields inherited from class org.openidentityplatform.openam.click.control.AbstractLink
disabled, imageSrc, label, parameters, renderLabelAndImage, tabindex, title
-
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 ActionLink()Create an ActionLink with no name defined.ActionLink(Object listener, String method)Create an ActionLink for the given listener object and listener method.ActionLink(String name)Create an ActionLink for the given name.ActionLink(String name, Object listener, String method)Create an ActionLink for the given name, listener object and listener method.ActionLink(String name, String label)Create an ActionLink for the given name and label.ActionLink(String name, String label, Object listener, String method)Create an ActionLink for the given name, label, listener object and listener method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbindRequestValue()This method binds the submitted request value to the ActionLink's value.StringgetHref()Return the ActionLink anchor <a> tag href attribute value.StringgetHref(Object value)Return the ActionLink anchor <a> tag href attribute for the given value.StringgetValue()Returns the ActionLink value if the action link was processed and has a value, or null otherwise.DoublegetValueDouble()Returns the action linkDoublevalue if the action link was processed and has a value, or null otherwise.IntegergetValueInteger()Returns the ActionLinkIntegervalue if the ActionLink was processed and has a value, or null otherwise.LonggetValueLong()Returns the ActionLinkLongvalue if the ActionLink was processed and has a value, or null otherwise.booleanisClicked()Returns true if the ActionLink was clicked, otherwise returns false.booleanonProcess()This method will set theisClicked()property to true if the ActionLink was clicked, and if an action callback listener was set this will be invoked.voidsetName(String name)Set the name of the Control.voidsetParent(Object parent)Set the parent of the ActionLink.voidsetValue(String value)Set the ActionLink value.voidsetValueObject(Object object)Set the value of the ActionLink using the given object.-
Methods inherited from class org.openidentityplatform.openam.click.control.AbstractLink
bindRequestParameters, defineParameter, getId, getImageSrc, getLabel, getParameter, getParameters, getParameterValues, getState, getTabIndex, getTag, getTitle, hasParameters, isAjaxTarget, isDisabled, isRenderLabelAndImage, removeState, render, renderImgTag, renderParameters, restoreState, saveState, setDisabled, setImageSrc, setLabel, setParameter, setParameters, setParameterValues, setRenderLabelAndImage, setState, setTabIndex, setTitle
-
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, onRender, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setStyle, toString
-
-
-
-
Field Detail
-
ACTION_LINK
public static final String ACTION_LINK
The action link parameter name:actionLink.- See Also:
- Constant Field Values
-
VALUE
public static final String VALUE
The value parameter name:value.- See Also:
- Constant Field Values
-
clicked
protected boolean clicked
The link is clicked.
-
-
Constructor Detail
-
ActionLink
public ActionLink(String name)
Create an ActionLink for the given name.Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.
- Parameters:
name- the action link name- Throws:
IllegalArgumentException- if the name is null
-
ActionLink
public ActionLink(String name, String label)
Create an ActionLink for the given name and label.Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.
- Parameters:
name- the action link namelabel- the action link label- Throws:
IllegalArgumentException- if the name is null
-
ActionLink
public ActionLink(Object listener, String method)
Create an ActionLink for the given listener object and listener method.- Parameters:
listener- the listener target objectmethod- the listener method to call- Throws:
IllegalArgumentException- if the name, listener or method is null or if the method is blank
-
ActionLink
public ActionLink(String name, Object listener, String method)
Create an ActionLink for the given name, listener object and listener method.Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.
- Parameters:
name- the action link namelistener- the listener target objectmethod- the listener method to call- Throws:
IllegalArgumentException- if the name, listener or method is null or if the method is blank
-
ActionLink
public ActionLink(String name, String label, Object listener, String method)
Create an ActionLink for the given name, label, listener object and listener method.Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.
- Parameters:
name- the action link namelabel- the action link labellistener- the listener target objectmethod- the listener method to call- Throws:
IllegalArgumentException- if the name, listener or method is null or if the method is blank
-
ActionLink
public ActionLink()
Create an ActionLink with no name defined. Please note the control's name must be defined before it is valid.
-
-
Method Detail
-
isClicked
public boolean isClicked()
Returns true if the ActionLink was clicked, otherwise returns false.- Returns:
- true if the ActionLink was clicked, otherwise returns false.
-
getHref
public String getHref(Object value)
Return the ActionLink anchor <a> tag href attribute for the given value. This method will encode the URL with the session ID if required usingHttpServletResponse.encodeURL().- Parameters:
value- the ActionLink value parameter- Returns:
- the ActionLink HTML href attribute
-
getHref
public String getHref()
Return the ActionLink anchor <a> tag href attribute value.- Specified by:
getHrefin classAbstractLink- Returns:
- the ActionLink anchor <a> tag HTML href attribute value
-
setName
public void setName(String name)
Set the name of the Control. Each control name must be unique in the containing Page model or the containing Form.Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.
- Specified by:
setNamein interfaceorg.openidentityplatform.openam.click.Control- Overrides:
setNamein classAbstractControl- Parameters:
name- of the control- Throws:
IllegalArgumentException- if the name is null- See Also:
Control.setName(String)
-
setParent
public void setParent(Object parent)
Set the parent of the ActionLink.- Specified by:
setParentin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
setParentin classAbstractControl- Parameters:
parent- the parent of the Control- Throws:
IllegalStateException- ifAbstractControl.nameis not definedIllegalArgumentException- if the given parent instance is referencingthisobject:if (parent == this)- See Also:
Control.setParent(Object)
-
getValue
public String getValue()
Returns the ActionLink value if the action link was processed and has a value, or null otherwise.- Returns:
- the ActionLink value if the ActionLink was processed
-
getValueDouble
public Double getValueDouble()
Returns the action linkDoublevalue if the action link was processed and has a value, or null otherwise.- Returns:
- the action link
Doublevalue if the action link was processed - Throws:
NumberFormatException- if the value cannot be parsed into a Double
-
getValueInteger
public Integer getValueInteger()
Returns the ActionLinkIntegervalue if the ActionLink was processed and has a value, or null otherwise.- Returns:
- the ActionLink
Integervalue if the action link was processed - Throws:
NumberFormatException- if the value cannot be parsed into an Integer
-
getValueLong
public Long getValueLong()
Returns the ActionLinkLongvalue if the ActionLink was processed and has a value, or null otherwise.- Returns:
- the ActionLink
Longvalue if the action link was processed - Throws:
NumberFormatException- if the value cannot be parsed into a Long
-
setValue
public void setValue(String value)
Set the ActionLink value.- Parameters:
value- the ActionLink value
-
setValueObject
public void setValueObject(Object object)
Set the value of the ActionLink using the given object.- Parameters:
object- the object value to set
-
bindRequestValue
public void bindRequestValue()
This method binds the submitted request value to the ActionLink's value.- Overrides:
bindRequestValuein classAbstractLink
-
onProcess
public boolean onProcess()
This method will set theisClicked()property to true if the ActionLink was clicked, and if an action callback listener was set this will be invoked.- Specified by:
onProcessin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
onProcessin classAbstractControl- Returns:
- true to continue Page event processing or false otherwise
- See Also:
Control.onProcess()
-
-