Class WCheckBox
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WCheckBox
-
- All Implemented Interfaces:
AjaxTarget
,AjaxTrigger
,BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Diagnosable
,Disableable
,Input
,Labelable
,Mandatable
,SelectionToggleable
,SubordinateTarget
,SubordinateTrigger
,WComponent
,WebComponent
,Serializable
- Direct Known Subclasses:
WToggleButton
public class WCheckBox extends AbstractInput implements AjaxTrigger, AjaxTarget, SubordinateTrigger, SubordinateTarget, SelectionToggleable
A WCheckBox is a wcomponent used to display a checkbox input field. Note that WCheckBox does not render any text. To display text for the check box, developers should associate a
WLabel
with the check box.The
isSelected()
method is used to determine if the checkbox has been ticked.- Since:
- 1.0.0
- Author:
- James Gifford, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WCheckBox.CheckBoxModel
Holds the extrinsic state information of the component.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractInput
AbstractInput.InputModel
-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
doHandleRequest(Request request)
Override handleRequest in order to perform processing for this component.String
getActionCommand()
Same asAbstractWComponent.getName()
.protected WCheckBox.CheckBoxModel
getComponentModel()
Returns the effective component model for this component.WComponentGroup<WCheckBox>
getGroup()
protected WCheckBox.CheckBoxModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.Boolean
getRequestValue(Request request)
Provide the value of the component on the Request.Boolean
getValue()
Provide the value of the component returned byDataBound.getData()
in the correct format.String
getValueAsString()
Returns the check box value as a String.boolean
isSelected()
Returns the state of the check box.boolean
isSubmitOnChange()
Deprecated.1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.protected WCheckBox.CheckBoxModel
newComponentModel()
Creates a new Component model.void
setGroup(WComponentGroup<WCheckBox> group)
Sets the checkbox group.void
setSelected(boolean selected)
Sets the state of the check box.void
setSubmitOnChange(boolean submitOnChange)
Deprecated.1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.void
toggleSelection(boolean selected)
Sets the selections for this component.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractInput
addValidator, beforeHandleRequest, createMandatoryDiagnostic, doHandleChanged, getActionObject, getActionOnChange, getDefaultSubmitButton, getDiagnostics, getValidators, handleRequest, isChangedInLastRequest, isCurrentAjaxTrigger, isDisabled, isEmpty, isMandatory, isPresent, isReadOnly, setActionObject, setActionOnChange, setChangedInLastRequest, setDefaultSubmitButton, setDisabled, setMandatory, setMandatory, setReadOnly, showErrorIndicatorsForComponent, showIndicatorsForComponent, showWarningIndicatorsForComponent, toString, validateComponent
-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContext, tidyUpUIContextForTree, validate, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanAware
getBean, getBeanProperty, getBeanValue, setBeanProperty
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanBound
isSearchAncestors, setBean
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanProviderBound
getBeanId, setBeanId, setBeanProvider
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Constructor Detail
-
WCheckBox
public WCheckBox()
Creates an initially unselected check box with no set text.
-
WCheckBox
public WCheckBox(boolean selected)
Creates a check box with the specified text and selection state.- Parameters:
selected
- if true, the check box is initially selected; otherwise, the check box is initially unselected
-
-
Method Detail
-
getValueAsString
public String getValueAsString()
Returns the check box value as a String.- Specified by:
getValueAsString
in interfaceInput
- Overrides:
getValueAsString
in classAbstractInput
- Returns:
- "true" if the checkbox is checked, otherwise null.
-
setGroup
public void setGroup(WComponentGroup<WCheckBox> group)
Sets the checkbox group. When a single grouped checkbox is targeted with aWSelectToggle
, all checkboxes in that group will be updated.- Parameters:
group
- The group to set.
-
getGroup
public WComponentGroup<WCheckBox> getGroup()
- Returns:
- the check box group.
-
toggleSelection
public final void toggleSelection(boolean selected)
Description copied from interface:SelectionToggleable
Sets the selections for this component.- Specified by:
toggleSelection
in interfaceSelectionToggleable
- Parameters:
selected
- if true, select everything. If false, deselect everything.
-
doHandleRequest
protected boolean doHandleRequest(Request request)
Override handleRequest in order to perform processing for this component. This implementation checks the checkbox state in the request.
- Specified by:
doHandleRequest
in classAbstractInput
- Parameters:
request
- the request being responded to.- Returns:
- true if the check box has changed
-
getRequestValue
public Boolean getRequestValue(Request request)
Provide the value of the component on the Request.If the component is not on the request, the components current value will be provided.
- Specified by:
getRequestValue
in interfaceInput
- Parameters:
request
- the request being responded to.- Returns:
- the value of this component on the Request, or its current state if it is not on the request.
-
getValue
public Boolean getValue()
Provide the value of the component returned byDataBound.getData()
in the correct format.If required, this method can convert the data into the correct type and also do any validation before the value is used.
- Specified by:
getValue
in interfaceInput
- Overrides:
getValue
in classAbstractInput
- Returns:
- the value of the component returned by
DataBound.getData()
in the correct format.
-
isSelected
public boolean isSelected()
Returns the state of the check box. True if selected, false if not.- Returns:
- true if the check box is selected, otherwise false
-
setSelected
public void setSelected(boolean selected)
Sets the state of the check box.- Parameters:
selected
- true if the check box is selected, otherwise false
-
setSubmitOnChange
@Deprecated public void setSubmitOnChange(boolean submitOnChange)
Deprecated.1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.Sets whether the form should be submitted when the checkbox is checked/unchecked. This sets the default option SubmitOnChange seen by all user sessions.- Parameters:
submitOnChange
- true to submit the form on change.
-
isSubmitOnChange
@Deprecated public boolean isSubmitOnChange()
Deprecated.1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.Indicates whether the form should be submitted when the checkbox is checked/unchecked.- Returns:
- true if the form should be submitted on change.
-
getActionCommand
public String getActionCommand()
Same asAbstractWComponent.getName()
. This method exists simply to clarify the relationship between the WCheckBox, its Action, and the ActionEvent sent to the execute() method of the Action.- Specified by:
getActionCommand
in interfaceInput
- Overrides:
getActionCommand
in classAbstractInput
- Returns:
- this checkbox's name.
-
newComponentModel
protected WCheckBox.CheckBoxModel newComponentModel()
Creates a new Component model.- Overrides:
newComponentModel
in classAbstractInput
- Returns:
- a new CheckBoxModel.
-
getComponentModel
protected WCheckBox.CheckBoxModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModel
in classAbstractInput
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WCheckBox.CheckBoxModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModel
in classAbstractInput
- Returns:
- the model for this component
-
-