net.sf.click.control
Class ActionButton

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Field
          extended bynet.sf.click.control.Button
              extended bynet.sf.click.control.ActionButton
All Implemented Interfaces:
Control, Serializable

public class ActionButton
extends Button

Provides a ActionButton control:   <input type="button"/>.

The ActionButton provides equivalent functionality to the ActionLink control, where you can attach action listeners to the button. When the button is clicked it will make a JavaScript GET request. This request is then processed by the ActionButton and its listener is invoked.

ActionButton Example

Example usage of the ActionButton:
 ActionButton actionButton = new ActionButton("button");
 actionButton.setListener(this, "onButtonClick");
 addControl(actionButton); 
Please Note do not add ActionButton instances to the Form object, as the GET request it generates will never be processed by the Form, and in turn the Form will not invoke the ActionButton's onProcess() method.

Author:
Malcolm Edgar
See Also:
ActionLink, Serialized Form

Field Summary
static String ACTION_BUTTON
          The action button parameter name:   actionButton.
protected  boolean clicked
          The button is clicked.
protected  Map parameters
          The link parameters map.
static String VALUE
          The value parameter name:   value.
 
Fields inherited from class net.sf.click.control.Field
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value
 
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
ActionButton()
          Create an ActionButton with no name defined.
ActionButton(Object listener, String method)
          Create an ActionButton for the given listener object and listener method.
ActionButton(String name)
          Create an ActionButton for the given name.
ActionButton(String name, Object listener, String method)
          Create an ActionButton for the given name, listener object and listener method.
ActionButton(String name, String label)
          Create an ActionButton for the given name and label.
ActionButton(String name, String label, Object listener, String method)
          Create an ActionButton 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 getOnClick()
          Return the ActionButton anchor <a> tag href attribute value.
 String getOnClick(Object value)
          Return the ActionButton onclick attribute for the given value.
 String getParameter(String name)
          Return the button request parameter value for the given name, or null if the parameter value does not exist.
 Map getParameters()
          Return the ActionButton parameters Map.
 String getValue()
          Returns the ActionButton value if the action link was processed and has a value, or null otherwise.
 Double getValueDouble()
          Returns the ActionButton Double value if the action button was processed and has a value, or null otherwise.
 Integer getValueInteger()
          Returns the ActionButton Integer value if the action button was processed and has a value, or null otherwise.
 Long getValueLong()
          Returns the ActionButton Long value if the action button was processed and has a value, or null otherwise.
 Object getValueObject()
          Return the value of the ActionButton.
 boolean hasParameters()
          Return true if the ActionButton has parameters or false otherwise.
 boolean isClicked()
          Returns true if the ActionButton was clicked, otherwise returns false.
 boolean onProcess()
          This method will set the isClicked() property to true if the ActionButton was clicked, and if an action callback listener was set this will be invoked.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the ActionButton.
 void setName(String name)
          Set the name of the Control.
 void setParameter(String name, String value)
          Set the button parameter with the given parameter name and value.
 void setParent(Object parent)
          Set the parent of the ActionButton.
 void setValue(String value)
          Set the ActionButton value.
 void setValueObject(Object object)
          Set the value of the field using the given object.
 
Methods inherited from class net.sf.click.control.Button
getControlSizeEst, getTag, getType, onRender, setOnClick
 
Methods inherited from class net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValidationJavaScript, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setWidth, validate
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACTION_BUTTON

public static final String ACTION_BUTTON
The action button parameter name:   actionButton.

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 button is clicked.


parameters

protected Map parameters
The link parameters map.

Constructor Detail

ActionButton

public ActionButton(String name)
Create an ActionButton for the given name.

Please note the name 'actionButton' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action button name
Throws:
IllegalArgumentException - if the name is null

ActionButton

public ActionButton(String name,
                    String label)
Create an ActionButton for the given name and label.

Please note the name 'actionButton' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action button name
label - the action button label
Throws:
IllegalArgumentException - if the name is null

ActionButton

public ActionButton(Object listener,
                    String method)
Create an ActionButton for the given listener object and listener method.

Parameters:
listener - the listener target object
method - the listener method to call
Throws:
IllegalArgumentException - if the name, listener or method is null or if the method is blank

ActionButton

public ActionButton(String name,
                    Object listener,
                    String method)
Create an ActionButton for the given name, listener object and listener method.

Please note the name 'actionButton' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action button name
listener - the listener target object
method - the listener method to call
Throws:
IllegalArgumentException - if the name, listener or method is null or if the method is blank

ActionButton

public ActionButton(String name,
                    String label,
                    Object listener,
                    String method)
Create an ActionButton for the given name, label, listener object and listener method.

Please note the name 'actionButton' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action button name
label - the action button label
listener - the listener target object
method - the listener method to call
Throws:
IllegalArgumentException - if the name, listener or method is null or if the method is blank

ActionButton

public ActionButton()
Create an ActionButton 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 ActionButton was clicked, otherwise returns false.

Returns:
true if the ActionButton was clicked, otherwise returns false.

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 'actionButton' is reserved as a control request parameter name and cannot be used as the name of the control.

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

Specified by:
setParent in interface Control
Overrides:
setParent in class Field
Parameters:
parent - the parent of the Control
Throws:
IllegalStateException - if AbstractControl.name is not defined
IllegalArgumentException - if the given parent instance is referencing this object: if (parent == this)
See Also:
Control.setParent(Object)

getOnClick

public String getOnClick(Object value)
Return the ActionButton onclick attribute for the given value. This method will encode the URL with the session ID if required using HttpServletResponse.encodeURL().

Parameters:
value - the ActionButton value parameter
Returns:
the ActionButton JavaScript href attribute

getOnClick

public String getOnClick()
Return the ActionButton anchor <a> tag href attribute value.

Overrides:
getOnClick in class Button
Returns:
the ActionButton anchor <a> tag HTML href attribute value

getParameter

public String getParameter(String name)
Return the button 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 button request parameter value

setParameter

public void setParameter(String name,
                         String value)
Set the button parameter with the given parameter name and value.

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

getParameters

public Map getParameters()
Return the ActionButton parameters Map.

Returns:
the ActionButton parameters Map

hasParameters

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

Returns:
true if the ActionButton has parameters on false otherwise

getValue

public String getValue()
Returns the ActionButton value if the action link was processed and has a value, or null otherwise.

Overrides:
getValue in class Field
Returns:
the ActionButton value if the ActionButton was processed

getValueDouble

public Double getValueDouble()
Returns the ActionButton Double value if the action button was processed and has a value, or null otherwise.

Returns:
the action button Double value if the action button was processed
Throws:
NumberFormatException - if the value cannot be parsed into a Double

getValueInteger

public Integer getValueInteger()
Returns the ActionButton Integer value if the action button was processed and has a value, or null otherwise.

Returns:
the ActionButton Integer value if the action button was processed
Throws:
NumberFormatException - if the value cannot be parsed into an Integer

getValueLong

public Long getValueLong()
Returns the ActionButton Long value if the action button was processed and has a value, or null otherwise.

Returns:
the ActionButton Long value if the action button was processed
Throws:
NumberFormatException - if the value cannot be parsed into a Long

setValue

public void setValue(String value)
Set the ActionButton value.

Overrides:
setValue in class Field
Parameters:
value - the ActionButton value

getValueObject

public Object getValueObject()
Return the value of the ActionButton.

Overrides:
getValueObject in class Field
Returns:
the value of the ActionButton

setValueObject

public void setValueObject(Object object)
Set the value of the field using the given object.

Overrides:
setValueObject in class Field
Parameters:
object - the object value to set

bindRequestValue

public void bindRequestValue()
This method binds the submitted request value to the ActionLink's value.

Overrides:
bindRequestValue in class Field

onProcess

public boolean onProcess()
This method will set the isClicked() property to true if the ActionButton was clicked, and if an action callback listener was set this will be invoked.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class Button
Returns:
true to continue Page event processing or false otherwise
See Also:
Control.onProcess()

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the ActionButton. Note the button label is rendered as the HTML "value" attribute.

Specified by:
render in interface Control
Overrides:
render in class Button
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()