Class WNumberField
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WNumberField
-
- All Implemented Interfaces:
AjaxTarget
,AjaxTrigger
,Autocompleteable
,AutocompleteableNumeric
,BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Diagnosable
,Disableable
,Input
,Labelable
,Mandatable
,SubordinateTarget
,SubordinateTrigger
,WComponent
,WebComponent
,Serializable
public class WNumberField extends AbstractInput implements AjaxTrigger, AjaxTarget, SubordinateTrigger, SubordinateTarget, AutocompleteableNumeric
A WNumberField is a wcomponent used to display a numeric input field. Use the method "
getValue()
" to get the number entered into the field by the user.Additional methods are available to return the value entered as an integer or decimal value, and there are methods which can be used to restrict the range of values which are allowed to be entered.
A number field differs from a text field in the way in which some user agents interact with it. For example, touchscreen devices may display a numeric data entry pad rather than an alphanumeric keyboard.
- Since:
- 1.0.0
- Author:
- Yiannis Paschalidis, Jonathan Austin, Mark Reeves
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WNumberField.NumberFieldModel
NumberFieldModel holds Extrinsic state management of the field.-
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
-
-
Constructor Summary
Constructors Constructor Description WNumberField()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAutocompleteSection(String sectionName)
Pre-pend anautocomplete
section to the value of anautocomplete
attribute for the current field.void
clearAutocomplete()
Clear theautocomplete
attribute.protected boolean
doHandleRequest(Request request)
Specific handle request processing for an input component is provided here.String
getAutocomplete()
int
getColumns()
Deprecated.1.3 size not used as it is incompatible with HTML specification.protected WNumberField.NumberFieldModel
getComponentModel()
Returns the effective component model for this component.int
getDecimalPlaces()
Retrieves the number of decimal places to use for this number field.BigDecimal
getMaxValue()
Retrieves the maximum allowable value for this number field.BigDecimal
getMinValue()
Retrieves the minimum allowable value for this number field.BigDecimal
getNumber()
Retrieves the numeric value of this field.protected WNumberField.NumberFieldModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.BigDecimal
getRequestValue(Request request)
Provide the value of the component on the Request.BigDecimal
getStep()
Retrieves the step value for this number field.String
getText()
Retrieves the text as entered by the user.BigDecimal
getValue()
Retrieves the numeric value of this field.String
getValueAsString()
Retrieves a String representation of the input field's value.protected void
handleRequestValue(BigDecimal value, boolean valid, String text)
Set the request value.boolean
isValidNumber()
Indicates whether the text value held in this field is a valid number.protected WNumberField.NumberFieldModel
newComponentModel()
Creates a new NumberFieldModel holds Extrinsic state management of the field.void
setAutocomplete(Numeric value)
Set the autocomplete attribute for a number field for a given numeric auto-fill value.void
setAutocompleteOff()
Turnautocomplete
off for the current field.void
setColumns(int columns)
Deprecated.1.3 size not used as it is incompatible with HTML specification.void
setData(Object data)
Sets the data that this component displays/edits.void
setDecimalPlaces(int decimalPlaces)
Sets the number of decimal places to use for this field.void
setMaxValue(double maxValue)
Sets the maximum allowable value for this number field.void
setMaxValue(long maxValue)
Sets the maximum allowable value for this number field.void
setMaxValue(BigDecimal maxValue)
Sets the maximum allowable value for this number field.void
setMinValue(double minValue)
Sets the minimum allowable value for this number field.void
setMinValue(long minValue)
Sets the minimum allowable value for this number field.void
setMinValue(BigDecimal minValue)
Sets the minimum allowable value for this number field.void
setNumber(double value)
Sets the value of this number field.void
setNumber(long value)
Sets the value of this number field.void
setNumber(BigDecimal value)
Sets the value of this number field.void
setStep(double step)
Sets the step value for this field.void
setStep(long step)
Sets the step value for this field.void
setStep(BigDecimal step)
Sets the step value for this field.void
setValue(double value)
Deprecated.void
setValue(long value)
Deprecated.UsesetNumber(long)
protected void
validateComponent(List<Diagnostic> diags)
Override WInput's validateComponent to perform futher validation on email addresses.protected void
validateNumber(List<Diagnostic> diags)
Performs validation of the number.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractInput
addValidator, beforeHandleRequest, createMandatoryDiagnostic, doHandleChanged, getActionCommand, 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
-
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, 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.autocomplete.Autocompleteable
isAutocompleteOff
-
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
-
-
-
-
Method Detail
-
getValueAsString
public String getValueAsString()
Description copied from class:AbstractInput
Retrieves a String representation of the input field's value.- Specified by:
getValueAsString
in interfaceInput
- Overrides:
getValueAsString
in classAbstractInput
- Returns:
- the number value, or the text entered by the user if there is no valid number.
-
doHandleRequest
protected 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.
- Specified by:
doHandleRequest
in classAbstractInput
- Parameters:
request
- the request being responded to.- Returns:
- true if the input component has changed, otherwise return false
-
handleRequestValue
protected void handleRequestValue(BigDecimal value, boolean valid, String text)
Set the request value.- Parameters:
value
- the number valuevalid
- true if valid valuetext
- the user text
-
getRequestValue
public BigDecimal 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 BigDecimal getValue()
Retrieves the numeric value of this field.- Specified by:
getValue
in interfaceInput
- Overrides:
getValue
in classAbstractInput
- Returns:
- the numeric value, or null if the field does not contain a valid number.
-
getText
public String getText()
Retrieves the text as entered by the user. This is not necessarily a valid date.- Returns:
- the text, as entered by the user.
-
isValidNumber
public boolean isValidNumber()
Indicates whether the text value held in this field is a valid number.- Returns:
- true if the field contains text which is a valid number, false otherwise.
-
getNumber
public BigDecimal getNumber()
Retrieves the numeric value of this field.- Returns:
- the numeric value, or null if the field does not contain a valid number.
-
setData
public void setData(Object data)
Sets the data that this component displays/edits. For bean aware components, this should only be called from handleRequest to set user-entered data.- Specified by:
setData
in interfaceDataBound
- Overrides:
setData
in classWBeanComponent
- Parameters:
data
- the data to set
-
setNumber
public void setNumber(BigDecimal value)
Sets the value of this number field.- Parameters:
value
- the value to set.
-
setNumber
public void setNumber(long value)
Sets the value of this number field.- Parameters:
value
- the value.
-
setNumber
public void setNumber(double value)
Sets the value of this number field.- Parameters:
value
- the value to set.
-
setValue
@Deprecated public void setValue(long value)
Deprecated.UsesetNumber(long)
Sets the value of this number field.- Parameters:
value
- the value.
-
setValue
@Deprecated public void setValue(double value)
Deprecated.Sets the value of this number field.- Parameters:
value
- the value to set.
-
getMinValue
public BigDecimal getMinValue()
Retrieves the minimum allowable value for this number field. The minimum value is enforced server-side using the WComponent validation framework, and may be enforced client-side.- Returns:
- the minimum allowable value, or null if there is no minimum.
-
setMinValue
public void setMinValue(long minValue)
Sets the minimum allowable value for this number field.- Parameters:
minValue
- the minimum allowable value.
-
setMinValue
public void setMinValue(double minValue)
Sets the minimum allowable value for this number field.- Parameters:
minValue
- the minimum allowable value.
-
setMinValue
public void setMinValue(BigDecimal minValue)
Sets the minimum allowable value for this number field.- Parameters:
minValue
- the minimum allowable value, or null for no minimum.
-
getMaxValue
public BigDecimal getMaxValue()
Retrieves the maximum allowable value for this number field. The minimum value is enforced server-side using the WComponent validation framework, and may be enforced client-side.- Returns:
- the maximum allowable value, or null if there is no maximum.
-
setMaxValue
public void setMaxValue(long maxValue)
Sets the maximum allowable value for this number field.- Parameters:
maxValue
- the maximum allowable value.
-
setMaxValue
public void setMaxValue(double maxValue)
Sets the maximum allowable value for this number field.- Parameters:
maxValue
- the maximum allowable value.
-
setMaxValue
public void setMaxValue(BigDecimal maxValue)
Sets the maximum allowable value for this number field.- Parameters:
maxValue
- the maximum allowable value, or null for no maximum.
-
getStep
public BigDecimal getStep()
Retrieves the step value for this number field. The step may be used by some user agents to provide a convenient increment/decrement function, such to a spinner control.- Returns:
- the step value, or null if there is no step value set.
-
setStep
public void setStep(long step)
Sets the step value for this field.- Parameters:
step
- the step value.
-
setStep
public void setStep(double step)
Sets the step value for this field.- Parameters:
step
- the step value.
-
setStep
public void setStep(BigDecimal step)
Sets the step value for this field.- Parameters:
step
- the step value, or null to use the default step.
-
getDecimalPlaces
public int getDecimalPlaces()
Retrieves the number of decimal places to use for this number field. A value of zero indicates that the fields should only accept integer values.- Returns:
- the number of decimal places to use.
-
setDecimalPlaces
public void setDecimalPlaces(int decimalPlaces)
Sets the number of decimal places to use for this field.- Parameters:
decimalPlaces
- the number of decimal places.
-
getColumns
@Deprecated public int getColumns()
Deprecated.1.3 size not used as it is incompatible with HTML specification.- Returns:
- the width of the input field in characters.
-
setColumns
@Deprecated public void setColumns(int columns)
Deprecated.1.3 size not used as it is incompatible with HTML specification.Sets the width of the input field in characters.- Parameters:
columns
- the number of characters to display.
-
validateComponent
protected void validateComponent(List<Diagnostic> diags)
Override WInput's validateComponent to perform futher validation on email addresses.- Overrides:
validateComponent
in classAbstractInput
- Parameters:
diags
- the list into which any validation diagnostics are added.
-
validateNumber
protected void validateNumber(List<Diagnostic> diags)
Performs validation of the number. Validation ensures that the entered text is a valid number, and is between the minimum/maximum values (if applicable).
Subclasses can override this method to perform more specific validation.
- Parameters:
diags
- the list into which any validation diagnostics are added.
-
newComponentModel
protected WNumberField.NumberFieldModel newComponentModel()
Creates a new NumberFieldModel holds Extrinsic state management of the field.- Overrides:
newComponentModel
in classAbstractInput
- Returns:
- a new NumberFieldModel
-
getComponentModel
protected WNumberField.NumberFieldModel 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 WNumberField.NumberFieldModel 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
-
setAutocomplete
public void setAutocomplete(Numeric value)
Description copied from interface:AutocompleteableNumeric
Set the autocomplete attribute for a number field for a given numeric auto-fill value.- Specified by:
setAutocomplete
in interfaceAutocompleteableNumeric
- Parameters:
value
- the type of number for auto-fill
-
getAutocomplete
public String getAutocomplete()
- Specified by:
getAutocomplete
in interfaceAutocompleteable
- Returns:
- the value of the
autocomplete
attribute applied to the current field.
-
setAutocompleteOff
public void setAutocompleteOff()
Description copied from interface:Autocompleteable
Turnautocomplete
off for the current field.- Specified by:
setAutocompleteOff
in interfaceAutocompleteable
-
addAutocompleteSection
public void addAutocompleteSection(String sectionName)
Description copied from interface:Autocompleteable
Pre-pend anautocomplete
section to the value of anautocomplete
attribute for the current field.- Specified by:
addAutocompleteSection
in interfaceAutocompleteable
- Parameters:
sectionName
- the name of the section being the part which would replace the asterisk in the formsection-*
-
clearAutocomplete
public void clearAutocomplete()
Description copied from interface:Autocompleteable
Clear theautocomplete
attribute.- Specified by:
clearAutocomplete
in interfaceAutocompleteable
-
-