net.sf.click.control
Class Button

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

public class Button
extends Field

Provides a Button control:   <input type='button'/>.

The Button control is used to render a JavaScript enabled button which can perform client side logic. The Button control provides no servier side processing. If server side processing is required use Submit instead.

Button Example

The example below adds a back button to a form, which when clicked returns to the previous page.
 Button backButton = new Button("back", " < Back ");
 backButton.setOnClick("history.back();");
 backButton.setTitle("Return to previous page");
 form.add(backButton); 
HTML output:
 <input type='button' name='back' value=' < Back ' onclick='history.back();'
        title='Return to previous page'/> 
See also W3C HTML reference INPUT

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

Field Summary
 
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
Button()
          Create a button with no name defined.
Button(String name)
          Create a button with the given name.
Button(String name, String label)
          Create a button with the given name and label.
 
Method Summary
 int getControlSizeEst()
          Return the estimated rendered control size in characters.
 String getOnClick()
          Returns the button onclick attribute value, or null if not defined.
 String getTag()
          Return the button's html tag: input.
 String getType()
          Return the input type: 'button'.
 boolean onProcess()
          Returns true, as buttons perform no server side logic.
 void onRender()
          This method does nothing.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the Button.
 void setOnClick(String value)
          Sets the button onclick attribute value.
 
Methods inherited from class net.sf.click.control.Field
bindRequestValue, getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValidationJavaScript, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setValueObject, 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, setName, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Button

public Button(String name)
Create a button with the given name.

Parameters:
name - the button name

Button

public Button(String name,
              String label)
Create a button with the given name and label. The button label is rendered as the HTML "value" attribute.

Parameters:
name - the button name
label - the button label

Button

public Button()
Create a button 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 button's html tag: input.

Overrides:
getTag in class AbstractControl
Returns:
this controls html tag
See Also:
AbstractControl.getTag()

getOnClick

public String getOnClick()
Returns the button onclick attribute value, or null if not defined.

Returns:
the button onclick attribute value, or null if not defined.

setOnClick

public void setOnClick(String value)
Sets the button onclick attribute value.

Parameters:
value - the onclick attribute value.

getType

public String getType()
Return the input type: 'button'.

Returns:
the input type: 'button'

onProcess

public boolean onProcess()
Returns true, as buttons perform no server side logic.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class Field
Returns:
true
See Also:
Field.onProcess()

onRender

public void onRender()
This method does nothing. Subclasses may override this method to perform pre rendering logic.

Specified by:
onRender in interface Control
Overrides:
onRender in class AbstractControl
See Also:
Control.onRender()

getControlSizeEst

public int getControlSizeEst()
Description copied from class: AbstractControl
Return the estimated rendered control size in characters.

Overrides:
getControlSizeEst in class AbstractControl
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()

render

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

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()