Class AbstractInput
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- All Implemented Interfaces:
BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Diagnosable
,Disableable
,Input
,Labelable
,Mandatable
,WComponent
,WebComponent
,Serializable
- Direct Known Subclasses:
AbstractWSelectList
,RadioButtonGroup
,WCheckBox
,WDateField
,WEmailField
,WFileWidget
,WMultiFileWidget
,WMultiTextField
,WNumberField
,WPartialDateField
,WPasswordField
,WPhoneNumberField
,WShuffler
,WTextField
,WTree
public abstract class AbstractInput extends WBeanComponent implements Input
Superclass for components that correspond to an input field.- Since:
- 1.0.0
- Author:
- James Gifford, Martin Shevchenko, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractInput.InputModel
InputModel holds Extrinsic state management of the field.-
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
-
-
Constructor Summary
Constructors Constructor Description AbstractInput()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addValidator(FieldValidator validator)
Adds a validator to the input field.protected boolean
beforeHandleRequest(Request request)
Handle before handle request processing.protected Diagnostic
createMandatoryDiagnostic()
This method is called by validateComponent to create the mandatory diagnostic error message if the mandatory validation check does not pass.protected void
doHandleChanged()
Perform change logic for this component.protected abstract boolean
doHandleRequest(Request request)
Specific handle request processing for an input component is provided here.String
getActionCommand()
Same as {#getValueAsString()}.Object
getActionObject()
Returns the data object that has been associated with this input component, else null.Action
getActionOnChange()
protected AbstractInput.InputModel
getComponentModel()
Returns the effective component model for this component.WButton
getDefaultSubmitButton()
List<Diagnostic>
getDiagnostics(int severity)
protected AbstractInput.InputModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.Iterator<FieldValidator>
getValidators()
Object
getValue()
Provide the value of the component returned byDataBound.getData()
in the correct format.String
getValueAsString()
Retrieves a String representation of the input field's value.void
handleRequest(Request request)
Override handleRequest in order to perform consistent processing for input components.boolean
isChangedInLastRequest()
Indicates if the input component was changed in the last request.boolean
isCurrentAjaxTrigger()
boolean
isDisabled()
Indicates whether the Disableable is disabled.boolean
isEmpty()
Indicates whether this input field is empty.boolean
isMandatory()
Indicates whether or not this component is mandatory.protected boolean
isPresent(Request request)
Determine if this component is on the Request.boolean
isReadOnly()
Indicates whether the input is read only in the given context.protected AbstractInput.InputModel
newComponentModel()
Creates a new model appropriate for this component.void
setActionObject(Object data)
Associates this input with a data object that can be easily accessed in the execute() method of the associated Action.void
setActionOnChange(Action actionOnChange)
Sets the action that you want run if the input is changed by the user.protected void
setChangedInLastRequest(boolean changed)
Set the changed flag to indicate if the component changed in the last request.void
setDefaultSubmitButton(WButton defaultSubmitButton)
Sets the button that should be submitted when the user hits enter key and cursor is inside this input field.void
setDisabled(boolean disabled)
Sets whether the Disableable is disabled.void
setMandatory(boolean mandatory)
Set whether or not this component is mandatory.void
setMandatory(boolean mandatory, String message)
Set whether or not this input is mandatory, and customise the error message that will be displayed.void
setReadOnly(boolean readOnly)
Sets whether the input is read only.protected void
showErrorIndicatorsForComponent(List<Diagnostic> diags)
This does not affect the diag list at all.protected void
showIndicatorsForComponent(List<Diagnostic> diags, int severity)
Iterates over theDiagnostic
s and finds the diagnostics that related to the current component.protected void
showWarningIndicatorsForComponent(List<Diagnostic> diags)
This does not affect the diag list at all.String
toString()
Creates a String representation of this component; usually for debugging purposes.protected void
validateComponent(List<Diagnostic> diags)
Override WComponent's validatorComponent in order to use the validators which have been added to this input field.-
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.Input
getRequestValue
-
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, 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
-
-
-
-
Method Detail
-
addValidator
public void addValidator(FieldValidator validator)
Adds a validator to the input field. Validators are not automatically called on form submission. Using aValidatingAction
or an explicit call toWComponent.validate(List)
will trigger validation on a WComponent tree.- Specified by:
addValidator
in interfaceInput
- Parameters:
validator
- the validator to add.
-
getValidators
public Iterator<FieldValidator> getValidators()
- Specified by:
getValidators
in interfaceInput
- Returns:
- the list of validators for this input field.
-
validateComponent
protected void validateComponent(List<Diagnostic> diags)
Override WComponent's validatorComponent in order to use the validators which have been added to this input field. Subclasses may still override this method, but it is suggested to call super.validateComponent to ensure that the validators are still used.- Overrides:
validateComponent
in classAbstractWComponent
- Parameters:
diags
- the list into which any validation diagnostics are added.
-
createMandatoryDiagnostic
protected Diagnostic createMandatoryDiagnostic()
This method is called by validateComponent to create the mandatory diagnostic error message if the mandatory validation check does not pass.
Subclasses may override this method to customise the message, however in most cases it is easier to supply a custom error message pattern to the setMandatory method.
- Returns:
- a new diagnostic for when mandatory validation fails.
-
setActionOnChange
public void setActionOnChange(Action actionOnChange)
Sets the action that you want run if the input is changed by the user. The action command will be set to the new value of the input.- Specified by:
setActionOnChange
in interfaceInput
- Parameters:
actionOnChange
- the action to execute when the input is changed by the user.
-
getActionOnChange
public Action getActionOnChange()
- Specified by:
getActionOnChange
in interfaceInput
- Returns:
- the action to execute when the input is changed by the user.
-
getActionObject
public Object getActionObject()
Returns the data object that has been associated with this input component, else null. For convenience, this data object is passed to the execute() method of the button's associated Action, in the ActionEvent parameter.- Specified by:
getActionObject
in interfaceInput
- Returns:
- the data object that has been associated with this input component.
-
setActionObject
public void setActionObject(Object data)
Associates this input with a data object that can be easily accessed in the execute() method of the associated Action.- Specified by:
setActionObject
in interfaceInput
- Parameters:
data
- the data object.
-
getActionCommand
public String getActionCommand()
Same as {#getValueAsString()}. This method exists simply to clarify the relationship between the input component, its Action, and the ActionEvent sent to the execute() method of the Action.- Specified by:
getActionCommand
in interfaceInput
- Returns:
- the current selection, as a string.
-
setDefaultSubmitButton
public void setDefaultSubmitButton(WButton defaultSubmitButton)
Sets the button that should be submitted when the user hits enter key and cursor is inside this input field.- Specified by:
setDefaultSubmitButton
in interfaceInput
- Parameters:
defaultSubmitButton
- the default submit button for this field.
-
getDefaultSubmitButton
public WButton getDefaultSubmitButton()
- Specified by:
getDefaultSubmitButton
in interfaceInput
- Returns:
- the button that will be submitted if the user hits the enter key when the cursor is in this field.
-
setMandatory
public void setMandatory(boolean mandatory, String message)
Set whether or not this input is mandatory, and customise the error message that will be displayed.- Specified by:
setMandatory
in interfaceInput
- Parameters:
mandatory
- true for mandatory, false for optional.message
- the message to display to the user on mandatory validation failure.
-
setMandatory
public void setMandatory(boolean mandatory)
Set whether or not this component is mandatory.- Specified by:
setMandatory
in interfaceMandatable
- Parameters:
mandatory
- true for mandatory, false for optional.
-
isMandatory
public boolean isMandatory()
Indicates whether or not this component is mandatory.- Specified by:
isMandatory
in interfaceMandatable
- Returns:
- true if the input is mandatory, false otherwise.
-
isReadOnly
public boolean isReadOnly()
Indicates whether the input is read only in the given context.- Specified by:
isReadOnly
in interfaceInput
- Returns:
- true if the input is read only, otherwise false.
-
setReadOnly
public void setReadOnly(boolean readOnly)
Sets whether the input is read only.- Specified by:
setReadOnly
in interfaceInput
- Parameters:
readOnly
- if true, the input is read only. If false, it is editable.
-
isDisabled
public boolean isDisabled()
Indicates whether the Disableable is disabled.- Specified by:
isDisabled
in interfaceDisableable
- Returns:
- true if the Disableable is disabled, otherwise false.
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether the Disableable is disabled.- Specified by:
setDisabled
in interfaceDisableable
- Parameters:
disabled
- if true, the Disableable is disabled. If false, it is enabled.
-
handleRequest
public final void handleRequest(Request request)
Override handleRequest in order to perform consistent processing for input components.To protect against client-side tampering of the request, disabled/readonly input fields will not have their handle request processing performed.
This method will call
doHandleRequest(Request)
for input components to process the request. If the input component has changed, then this method will calldoHandleChanged()
and set theisChangedInLastRequest()
flag.- Specified by:
handleRequest
in interfaceWComponent
- Overrides:
handleRequest
in classAbstractWComponent
- Parameters:
request
- the request being responded to.
-
beforeHandleRequest
protected boolean beforeHandleRequest(Request request)
Handle before handle request processing.- Parameters:
request
- the request being responded to.- Returns:
- true to continue
-
doHandleRequest
protected abstract boolean doHandleRequest(Request request)
Specific handle request processing for an input component is provided here.Input components are required to determine if the component has changed in the request, set the component data to the new value (if changed) and return the changed flag.
- Parameters:
request
- the request being responded to.- Returns:
- true if the input component has changed, otherwise return false
-
doHandleChanged
protected void doHandleChanged()
Perform change logic for this component.Reset focus ONLY if the current Request is an Ajax request. See https://github.com/BorderTech/wcomponents/issues/501.
-
isPresent
protected boolean isPresent(Request request)
Determine if this component is on the Request.- Parameters:
request
- the request being responded to.- Returns:
- true if this component is on the Request, otherwise return false.
-
getValue
public Object 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
- Returns:
- the value of the component returned by
DataBound.getData()
in the correct format.
-
getValueAsString
public String getValueAsString()
Retrieves a String representation of the input field's value.- Specified by:
getValueAsString
in interfaceInput
- Returns:
- the String representation of the input field's value
-
isEmpty
public boolean isEmpty()
Indicates whether this input field is empty. An input is considered empty if the value is null or an empty String.
-
isChangedInLastRequest
public boolean isChangedInLastRequest()
Indicates if the input component was changed in the last request.- Specified by:
isChangedInLastRequest
in interfaceInput
- Returns:
- true if the input was changed in the last request.
-
setChangedInLastRequest
protected void setChangedInLastRequest(boolean changed)
Set the changed flag to indicate if the component changed in the last request.- Parameters:
changed
- true if the value changed in the request
-
isCurrentAjaxTrigger
public final boolean isCurrentAjaxTrigger()
- Returns:
true
if the current Input is also the current Ajax trigger.
-
toString
public String toString()
Description copied from class:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractWComponent
- Returns:
- a String representation of this component, for debugging purposes.
-
showIndicatorsForComponent
protected void showIndicatorsForComponent(List<Diagnostic> diags, int severity)
Iterates over theDiagnostic
s and finds the diagnostics that related to the current component.- Parameters:
diags
- A List of Diagnostic objects.severity
- A Diagnostic severity code. e.g.Diagnostic.ERROR
-
showErrorIndicatorsForComponent
protected final void showErrorIndicatorsForComponent(List<Diagnostic> diags)
This does not affect the diag list at all. The ValidatableComponent should visually mark any fields or blocks that have errors in the given diag list.
- Overrides:
showErrorIndicatorsForComponent
in classAbstractWComponent
- Parameters:
diags
- the list of diagnostics for this component.
-
showWarningIndicatorsForComponent
protected final void showWarningIndicatorsForComponent(List<Diagnostic> diags)
This does not affect the diag list at all. The ValidatableComponent should visually mark any fields or blocks that have warnings in the given diag list.
- Overrides:
showWarningIndicatorsForComponent
in classAbstractWComponent
- Parameters:
diags
- the list of diagnostics for this component.
-
getDiagnostics
public List<Diagnostic> getDiagnostics(int severity)
- Specified by:
getDiagnostics
in interfaceDiagnosable
- Parameters:
severity
- the diagnostic level we are interested in- Returns:
- the list of diagnostics for the component.
-
newComponentModel
protected AbstractInput.InputModel newComponentModel()
Creates a new model appropriate for this component.- Overrides:
newComponentModel
in classWBeanComponent
- Returns:
- a new
BeanAndProviderBoundComponentModel
.
-
getComponentModel
protected AbstractInput.InputModel 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 classWBeanComponent
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected AbstractInput.InputModel 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 classWBeanComponent
- Returns:
- the model for this component
-
-