|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.control.AbstractControl net.sf.click.control.AbstractLink net.sf.click.control.ActionLink
Provides a Action Link control: <a href=""></a>.
Action Link |
getHref()
, or the entire ActionLink anchor tag using
AbstractControl.toString()
.
ActionLink support invoking control listeners.
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 to
getHref()
:
<a href="$logoutLink.href" title="Click to Logout">Logout</a>
ActionLink can also support a value parameter which is accessable
using getValue()
.
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
AbstractLink
,
Submit
,
Serialized FormField Summary | |
static String |
ACTION_LINK
The action link parameter name: actionLink. |
protected boolean |
clicked
The link is clicked. |
static String |
VALUE
The value parameter name: value. |
Fields inherited from class net.sf.click.control.AbstractLink |
disabled, imageSrc, label, parameters, tabindex, title |
Fields inherited from class net.sf.click.control.AbstractControl |
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface net.sf.click.Control |
CONTROL_MESSAGES |
Constructor Summary | |
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 | |
void |
bindRequestValue()
This method binds the submitted request value to the ActionLink's value. |
String |
getHref()
Return the ActionLink anchor <a> tag href attribute value. |
String |
getHref(Object value)
Return the ActionLink anchor <a> tag href attribute for the given value. |
String |
getValue()
Returns the ActionLink value if the action link was processed and has a value, or null otherwise. |
Double |
getValueDouble()
Returns the action link Double value if the action link was processed and has a value, or null otherwise. |
Integer |
getValueInteger()
Returns the ActionLink Integer value if the ActionLink was processed and has a value, or null otherwise. |
Long |
getValueLong()
Returns the ActionLink Long value if the ActionLink was processed and has a value, or null otherwise. |
boolean |
isClicked()
Returns true if the ActionLink was clicked, otherwise returns false. |
boolean |
onProcess()
This method will set the isClicked() property to true if the
ActionLink was clicked, and if an action callback listener was set
this will be invoked. |
void |
setName(String name)
Set the name of the Control. |
void |
setParent(Object parent)
Set the parent of the ActionLink. |
void |
setValue(String value)
Set the ActionLink value. |
void |
setValueObject(Object object)
Set the value of the ActionLink using the given object. |
Methods inherited from class net.sf.click.control.AbstractLink |
getHtmlImports, getId, getImageSrc, getLabel, getParameter, getParameters, getTabIndex, getTag, getTitle, hasParameters, isDisabled, render, setDisabled, setImageSrc, setLabel, setParameter, setTabIndex, setTitle |
Methods inherited from class net.sf.click.control.AbstractControl |
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getControlSizeEst, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onInit, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setStyle, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final String ACTION_LINK
public static final String VALUE
protected boolean clicked
Constructor Detail |
public ActionLink(String name)
name
- the action link name
IllegalArgumentException
- if the name is nullpublic ActionLink(String name, String label)
name
- the action link namelabel
- the action link label
IllegalArgumentException
- if the name is nullpublic ActionLink(Object listener, String method)
listener
- the listener target objectmethod
- the listener method to call
IllegalArgumentException
- if the name, listener or method is null
or if the method is blankpublic ActionLink(String name, Object listener, String method)
name
- the action link namelistener
- the listener target objectmethod
- the listener method to call
IllegalArgumentException
- if the name, listener or method is null
or if the method is blankpublic ActionLink(String name, String label, Object listener, String method)
name
- the action link namelabel
- the action link labellistener
- the listener target objectmethod
- the listener method to call
IllegalArgumentException
- if the name, listener or method is null
or if the method is blankpublic ActionLink()
Method Detail |
public boolean isClicked()
public String getHref(Object value)
value
- the ActionLink value parameter
public String getHref()
getHref
in class AbstractLink
public void setName(String name)
setName
in interface Control
setName
in class AbstractControl
name
- of the control
IllegalArgumentException
- if the name is nullControl.setName(String)
public void setParent(Object parent)
setParent
in interface Control
setParent
in class AbstractControl
parent
- the parent of the Control
IllegalStateException
- if AbstractControl.name
is not defined
IllegalArgumentException
- if the given parent instance is
referencing this object: if (parent == this)Control.setParent(Object)
public String getValue()
public Double getValueDouble()
NumberFormatException
- if the value cannot be parsed into a Doublepublic Integer getValueInteger()
NumberFormatException
- if the value cannot be parsed into an Integerpublic Long getValueLong()
NumberFormatException
- if the value cannot be parsed into a Longpublic void setValue(String value)
value
- the ActionLink valuepublic void setValueObject(Object object)
object
- the object value to setpublic void bindRequestValue()
public boolean onProcess()
isClicked()
property to true if the
ActionLink was clicked, and if an action callback listener was set
this will be invoked.
onProcess
in interface Control
onProcess
in class AbstractControl
Control.onProcess()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |