org.apache.click.control
Class ActionButton

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.control.Field
          extended by org.apache.click.control.Button
              extended by org.apache.click.control.ActionButton
All Implemented Interfaces:
Serializable, Control, Stateful

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.

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<String,Object> parameters
          The button parameters map.
static String VALUE
          The value parameter name:   value.
 
Fields inherited from class org.apache.click.control.Field
disabled, error, focus, form, help, label, labelStyle, labelStyleClass, parentStyleClassHint, parentStyleHint, readonly, required, tabindex, title, trim, validate, value
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.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
protected  void bindRequestParameters(Context context)
          This method binds the submitted request parameters to the buttons parameters.
 void bindRequestValue()
          This method binds the submitted request value to the ActionButton's value.
 void defineParameter(String name)
          Defines a button parameter that will have its value bound to a matching request parameter.
 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<String,Object> 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 isAjaxTarget(Context context)
          Returns true if this control is an AJAX target, 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 setParameters(Map parameters)
          Set the ActionButton parameter map.
 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 org.apache.click.control.Button
getControlSizeEst, getTag, getType, setOnClick
 
Methods inherited from class org.apache.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getState, getTabIndex, getTextAlign, getTitle, getValidate, getValidationJavaScript, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setWidth, validate
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, 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<String,Object> parameters
The button 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<String,Object> getParameters()
Return the ActionButton parameters Map.

Returns:
the ActionButton parameters Map

setParameters

public void setParameters(Map parameters)
Set the ActionButton parameter map.

Parameters:
parameters - the button parameter map

defineParameter

public void defineParameter(String name)
Defines a button parameter that will have its value bound to a matching request parameter. setParameter implicitly defines a parameter as well.

Please note: parameters need only be defined for Ajax requests. For non-Ajax requests, all incoming request parameters are bound, whether they are defined or not. This behavior may change in a future release.

Also note: button parameters are bound to request parameters during the onProcess() event, so button parameters must be defined in the Page constructor or onInit() event.

Parameters:
name - the name of the parameter to define

hasParameters

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

Returns:
true if the ActionButton has parameters on false otherwise

isAjaxTarget

public boolean isAjaxTarget(Context context)
Description copied from class: AbstractControl
Returns true if this control is an AJAX target, false otherwise.

The control is defined as an Ajax target if the control ID is send as a request parameter.

Specified by:
isAjaxTarget in interface Control
Overrides:
isAjaxTarget in class AbstractControl
Parameters:
context - the request context
Returns:
true if this control is an AJAX target, 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 ActionButton'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:
Field.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()

bindRequestParameters

protected void bindRequestParameters(Context context)
This method binds the submitted request parameters to the buttons parameters.

For non-Ajax requests this method will bind all incoming request parameters to the link. For Ajax requests this method will only bind the parameters already defined on the link.

Parameters:
context - the request context