net.sf.click.control
Class Checkbox

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

public class Checkbox
extends Field

Provides a Checkbox control:   <input type='checkbox'>.

Checkbox
Checkbox supports the Field.required property and Control listeners.

See also W3C HTML reference INPUT

Author:
Malcolm Edgar
See Also:
Serialized Form

Field Summary
protected  boolean checked
          The field checked value.
protected static String VALIDATE_CHECKBOX_FUNCTION
          The field validation JavaScript function template.
 
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
Checkbox()
          Create a Checkbox field with no name defined.
Checkbox(String name)
          Create a Checkbox field with the given name.
Checkbox(String name, boolean required)
          Create a Checkbox field with the given name and required flag.
Checkbox(String name, String label)
          Create a Checkbox field with the given name and label.
 
Method Summary
 void bindRequestValue()
          Set the checked property to true if the fields value is submitted.
 String getTag()
          Return the checkbox's html tag: input.
 String getType()
          Return the input type: 'checkbox'.
 String getValidationJavaScript()
          Return the Checkbox JavaScript client side validation function.
 String getValue()
          Returns "true" if the checkbox is checked, or false otherwise.
 Object getValueObject()
          Return the field Boolean value.
 boolean isChecked()
          Return true if the checkbox is checked, or false otherwise.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the Checkbox.
 void setChecked(boolean value)
          Set the selected value of the checkbox.
 void setValue(String value)
          Set checked value of the field.
 void setValueObject(Object object)
          Set the checked value of the field using the given object.
 void validate()
          Validate the Checkbox request submission.
 
Methods inherited from class net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setWidth
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getControlSizeEst, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onRender, 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
 

Field Detail

VALIDATE_CHECKBOX_FUNCTION

protected static final String VALIDATE_CHECKBOX_FUNCTION
The field validation JavaScript function template. The function template arguments are:

See Also:
Constant Field Values

checked

protected boolean checked
The field checked value.

Constructor Detail

Checkbox

public Checkbox(String name)
Create a Checkbox field with the given name.

Parameters:
name - the name of the field

Checkbox

public Checkbox(String name,
                String label)
Create a Checkbox field with the given name and label.

Parameters:
name - the name of the field
label - the label of the field

Checkbox

public Checkbox(String name,
                boolean required)
Create a Checkbox field with the given name and required flag.

Parameters:
name - the name of the field
required - the name required status

Checkbox

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

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

isChecked

public boolean isChecked()
Return true if the checkbox is checked, or false otherwise.

Returns:
true if the checkbox is checked.

setChecked

public void setChecked(boolean value)
Set the selected value of the checkbox.

Parameters:
value - the selected value

getType

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

Returns:
the input type 'checkbox'

getValue

public String getValue()
Returns "true" if the checkbox is checked, or false otherwise.

Overrides:
getValue in class Field
Returns:
the Field value
See Also:
Field.getValue()

setValue

public void setValue(String value)
Set checked value of the field. If the given value is null, the checked value is set to false.

Overrides:
setValue in class Field
Parameters:
value - the Field value
See Also:
Field.setValue(String)

getValueObject

public Object getValueObject()
Return the field Boolean value.

Overrides:
getValueObject in class Field
Returns:
the object representation of the Field value
See Also:
Field.getValueObject()

setValueObject

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

Overrides:
setValueObject in class Field
Parameters:
object - the object value to set
See Also:
Field.setValueObject(Object)

getValidationJavaScript

public String getValidationJavaScript()
Return the Checkbox JavaScript client side validation function.

Overrides:
getValidationJavaScript in class Field
Returns:
the field JavaScript client side validation function

bindRequestValue

public void bindRequestValue()
Set the checked property to true if the fields value is submitted.

Overrides:
bindRequestValue in class Field

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the Checkbox.

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

validate

public void validate()
Validate the Checkbox request submission.

If a checked value is Field.required and the Checkbox is not checked the error message defined by not-checked-error property will be displayed.

Overrides:
validate in class Field