org.apache.click.element
Class Element

java.lang.Object
  extended by org.apache.click.element.Element
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ResourceElement

public class Element
extends Object
implements Serializable

Provides a base class for rendering HTML elements, for example JavaScript (<script>) and Cascading Stylesheets (<link> / <style>).

Subclasses should override getTag() to return a specific HTML tag.

See Also:
Serialized Form

Constructor Summary
Element()
           
 
Method Summary
protected  void appendAttributes(HtmlStringBuffer buffer)
          Append all the Element attributes to the specified buffer.
 String getAttribute(String name)
          Return the HTML attribute with the given name, or null if the attribute does not exist.
 Map<String,String> getAttributes()
          Return the Element attributes Map.
 Context getContext()
          Return the thread local Context.
 String getId()
          Return the "id" attribute value or null if no id is defined.
 String getTag()
          Returns the Element HTML tag, the default value is null.
 boolean hasAttribute(String name)
          Returns true if specified attribute is defined, false otherwise.
 boolean hasAttributes()
          Return true if the Element has attributes or false otherwise.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the Element to the specified buffer.
 void setAttribute(String name, String value)
          Set the Element attribute with the given attribute name and value.
 void setId(String id)
          Set the HTML id attribute for the with the given value.
 String toString()
          Return the HTML string representation of the Element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Element

public Element()
Method Detail

getTag

public String getTag()
Returns the Element HTML tag, the default value is null.

Subclasses should override this method and return the correct tag.

Returns:
this Element HTML tag

getAttribute

public String getAttribute(String name)
Return the HTML attribute with the given name, or null if the attribute does not exist.

Parameters:
name - the name of link HTML attribute
Returns:
the link HTML attribute

setAttribute

public void setAttribute(String name,
                         String value)
Set the Element attribute with the given attribute name and value.

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

getAttributes

public Map<String,String> getAttributes()
Return the Element attributes Map.

Returns:
the Element attributes Map.

hasAttributes

public boolean hasAttributes()
Return true if the Element has attributes or false otherwise.

Returns:
true if the Element has attributes on false otherwise

hasAttribute

public boolean hasAttribute(String name)
Returns true if specified attribute is defined, false otherwise.

Parameters:
name - the specified attribute to check
Returns:
true if name is a defined attribute

getId

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

Returns:
HTML element identifier attribute "id" value or null if no id is defined

setId

public void setId(String id)
Set the HTML id attribute for the with the given value.

Parameters:
id - the element HTML id attribute value to set

getContext

public Context getContext()
Return the thread local Context.

Returns:
the thread local Context

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the Element to the specified buffer.

If getTag() returns null, this method will return an empty string.

Parameters:
buffer - the specified buffer to render the Element output to

toString

public String toString()
Return the HTML string representation of the Element.

Overrides:
toString in class Object
Returns:
the HTML string representation of the Element

appendAttributes

protected void appendAttributes(HtmlStringBuffer buffer)
Append all the Element attributes to the specified buffer.

Parameters:
buffer - the specified buffer to append all the attributes