net.sf.click.control
Class AbstractLink

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.AbstractLink
All Implemented Interfaces:
Control, Serializable
Direct Known Subclasses:
ActionLink, PageLink

public abstract class AbstractLink
extends AbstractControl

Provides a Abstract Link control:   <a href=""></a>.

See also the W3C HTML reference: A Links

Author:
Malcolm Edgar
See Also:
ActionLink, Submit, Serialized Form

Field Summary
protected  boolean disabled
          The Field disabled value.
protected  String imageSrc
          The image src path attribute.
protected  String label
          The link display label.
protected  Map parameters
          The link parameters map.
protected  int tabindex
          The link 'tabindex' attribute.
protected  String title
          The link title attribute, which acts as a tooltip help message.
 
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
AbstractLink()
          Create an AbstractLink with no name defined.
AbstractLink(String name)
          Create an AbstractLink for the given name.
 
Method Summary
abstract  String getHref()
          Return the AbstractLink anchor <a> tag href attribute.
 String getHtmlImports()
          This method returns null.
 String getId()
          Return the "id" attribute value if defined, or null otherwise.
 String getImageSrc()
          Return the image src path attribute.
 String getLabel()
          Return the label for the AbstractLink.
 String getParameter(String name)
          Return the link request parameter value for the given name, or null if the parameter value does not exist.
 Map getParameters()
          Return the AbstractLink parameters Map.
 int getTabIndex()
          Return the link "tabindex" attribute value.
 String getTag()
          Return the links html tag: a.
 String getTitle()
          Return the 'title' attribute, or null if not defined.
 boolean hasParameters()
          Return true if the AbstractLink has parameters or false otherwise.
 boolean isDisabled()
          Return true if the AbstractLink is a disabled.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the anchor link.
 void setDisabled(boolean disabled)
          Set the disabled flag.
 void setImageSrc(String src)
          Set the image src path attribute.
 void setLabel(String label)
          Set the label for the ActionLink.
 void setParameter(String name, String value)
          Set the link parameter with the given parameter name and value.
 void setTabIndex(int tabindex)
          Set the link "tabindex" attribute value.
 void setTitle(String value)
          Set the 'title' attribute tooltip message.
 
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, onProcess, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setName, setParent, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 AbstractLink AbstractControl.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.


parameters

protected Map parameters
The link parameters map.


tabindex

protected int tabindex
The link 'tabindex' attribute.


title

protected String title
The link title attribute, which acts as a tooltip help message.

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 links html tag: a.

Overrides:
getTag in class AbstractControl
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 using HttpServletResponse.encodeURL().

Returns:
the AbstractLink HTML href attribute

getHtmlImports

public String getHtmlImports()
This method returns null.

Specified by:
getHtmlImports in interface Control
Overrides:
getHtmlImports in class AbstractControl
Returns:
null
See Also:
Control.getHtmlImports()

getImageSrc

public String getImageSrc()
Return the image src path attribute. If the image src is defined then a <img/> element will rendered inside the anchor link when using the AbstractLink AbstractControl.toString() method, and the label will not be rendered.

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 a <img/> element will rendered inside the anchor link when using the AbstractLink AbstractControl.toString() method, and the label will not be rendered.

Parameters:
src - the image src path attribute

getId

public String getId()
Return the "id" attribute value if defined, or null otherwise.

Specified by:
getId in interface Control
Overrides:
getId in class AbstractControl
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:

getName() + ".label"
If not found then the message will be looked up in the /click-control.properties file using the same key. If a value still cannot be found then the ActinLink name will be converted into a label using the method: ClickUtils.toLabel(String)

For examle given a OrderPage with the properties file OrderPage.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,
                         String value)
Set the link parameter with the given parameter name and value. You would generally use parameter if you were creating the entire AbstractLink programatically and rendering it with the AbstractControl.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:
 $editLink 
Will render the HTML as:
 <a href="/mycorp/edit-customer.htm?customerId=13490">Edit Customer</a> 

Parameters:
name - the attribute name
value - the attribute value
Throws:
IllegalArgumentException - if name parameter is null

getParameters

public Map getParameters()
Return the AbstractLink parameters Map.

Returns:
the AbstractLink parameters Map

hasParameters

public boolean hasParameters()
Return true if the AbstractLink has parameters or false otherwise.

Returns:
true if the AbstractLink has parameters on 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:

getName() + ".title"
If not found then the message will be looked up in the /click-control.properties file using the same key.

For examle given a ItemsPage with the properties file ItemPage.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()

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, see AbstractControl.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:
render in interface Control
Overrides:
render in class AbstractControl
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()