org.apache.click.control
Class Checkbox

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

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

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 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
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.
 boolean onProcess()
          Process the request Context setting the checked value if selected and invoking the control's listener if defined.
 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 org.apache.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getState, getTabIndex, getTextAlign, getTitle, getValidate, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setWidth
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, 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

onProcess

public boolean onProcess()
Process the request Context setting the checked value if selected and invoking the control's listener if defined.

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

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