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 classAbstractInput.InputModelInputModel 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 voidaddValidator(FieldValidator validator)Adds a validator to the input field.protected booleanbeforeHandleRequest(Request request)Handle before handle request processing.protected DiagnosticcreateMandatoryDiagnostic()This method is called by validateComponent to create the mandatory diagnostic error message if the mandatory validation check does not pass.protected voiddoHandleChanged()Perform change logic for this component.protected abstract booleandoHandleRequest(Request request)Specific handle request processing for an input component is provided here.StringgetActionCommand()Same as {#getValueAsString()}.ObjectgetActionObject()Returns the data object that has been associated with this input component, else null.ActiongetActionOnChange()protected AbstractInput.InputModelgetComponentModel()Returns the effective component model for this component.WButtongetDefaultSubmitButton()List<Diagnostic>getDiagnostics(int severity)protected AbstractInput.InputModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.Iterator<FieldValidator>getValidators()ObjectgetValue()Provide the value of the component returned byDataBound.getData()in the correct format.StringgetValueAsString()Retrieves a String representation of the input field's value.voidhandleRequest(Request request)Override handleRequest in order to perform consistent processing for input components.booleanisChangedInLastRequest()Indicates if the input component was changed in the last request.booleanisCurrentAjaxTrigger()booleanisDisabled()Indicates whether the Disableable is disabled.booleanisEmpty()Indicates whether this input field is empty.booleanisMandatory()Indicates whether or not this component is mandatory.protected booleanisPresent(Request request)Determine if this component is on the Request.booleanisReadOnly()Indicates whether the input is read only in the given context.protected AbstractInput.InputModelnewComponentModel()Creates a new model appropriate for this component.voidsetActionObject(Object data)Associates this input with a data object that can be easily accessed in the execute() method of the associated Action.voidsetActionOnChange(Action actionOnChange)Sets the action that you want run if the input is changed by the user.protected voidsetChangedInLastRequest(boolean changed)Set the changed flag to indicate if the component changed in the last request.voidsetDefaultSubmitButton(WButton defaultSubmitButton)Sets the button that should be submitted when the user hits enter key and cursor is inside this input field.voidsetDisabled(boolean disabled)Sets whether the Disableable is disabled.voidsetMandatory(boolean mandatory)Set whether or not this component is mandatory.voidsetMandatory(boolean mandatory, String message)Set whether or not this input is mandatory, and customise the error message that will be displayed.voidsetReadOnly(boolean readOnly)Sets whether the input is read only.protected voidshowErrorIndicatorsForComponent(List<Diagnostic> diags)This does not affect the diag list at all.protected voidshowIndicatorsForComponent(List<Diagnostic> diags, int severity)Iterates over theDiagnostics and finds the diagnostics that related to the current component.protected voidshowWarningIndicatorsForComponent(List<Diagnostic> diags)This does not affect the diag list at all.StringtoString()Creates a String representation of this component; usually for debugging purposes.protected voidvalidateComponent(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 aValidatingActionor an explicit call toWComponent.validate(List)will trigger validation on a WComponent tree.- Specified by:
addValidatorin interfaceInput- Parameters:
validator- the validator to add.
-
getValidators
public Iterator<FieldValidator> getValidators()
- Specified by:
getValidatorsin 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:
validateComponentin 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:
setActionOnChangein interfaceInput- Parameters:
actionOnChange- the action to execute when the input is changed by the user.
-
getActionOnChange
public Action getActionOnChange()
- Specified by:
getActionOnChangein 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:
getActionObjectin 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:
setActionObjectin 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:
getActionCommandin 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:
setDefaultSubmitButtonin interfaceInput- Parameters:
defaultSubmitButton- the default submit button for this field.
-
getDefaultSubmitButton
public WButton getDefaultSubmitButton()
- Specified by:
getDefaultSubmitButtonin 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:
setMandatoryin 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:
setMandatoryin interfaceMandatable- Parameters:
mandatory- true for mandatory, false for optional.
-
isMandatory
public boolean isMandatory()
Indicates whether or not this component is mandatory.- Specified by:
isMandatoryin 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:
isReadOnlyin 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:
setReadOnlyin 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:
isDisabledin interfaceDisableable- Returns:
- true if the Disableable is disabled, otherwise false.
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether the Disableable is disabled.- Specified by:
setDisabledin 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:
handleRequestin interfaceWComponent- Overrides:
handleRequestin 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:
getValuein 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:
getValueAsStringin 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:
isChangedInLastRequestin 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:
trueif the current Input is also the current Ajax trigger.
-
toString
public String toString()
Description copied from class:AbstractWComponentCreates a String representation of this component; usually for debugging purposes.- Overrides:
toStringin classAbstractWComponent- Returns:
- a String representation of this component, for debugging purposes.
-
showIndicatorsForComponent
protected void showIndicatorsForComponent(List<Diagnostic> diags, int severity)
Iterates over theDiagnostics 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:
showErrorIndicatorsForComponentin 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:
showWarningIndicatorsForComponentin classAbstractWComponent- Parameters:
diags- the list of diagnostics for this component.
-
getDiagnostics
public List<Diagnostic> getDiagnostics(int severity)
- Specified by:
getDiagnosticsin 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:
newComponentModelin 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:
getComponentModelin 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:
getOrCreateComponentModelin classWBeanComponent- Returns:
- the model for this component
-
-