Class WTextField
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WTextField
-
- All Implemented Interfaces:
AjaxTarget,AjaxTrigger,Autocompleteable,AutocompleteableDate,AutocompleteableEmail,AutocompleteableNumeric,AutocompleteablePassword,AutocompleteablePhone,AutocompleteableText,AutocompleteableURL,BeanAware,BeanBound,BeanProviderBound,DataBound,Diagnosable,Disableable,Input,Labelable,Mandatable,Placeholderable,SubordinateTarget,SubordinateTrigger,WComponent,WebComponent,Serializable
- Direct Known Subclasses:
WTextArea
public class WTextField extends AbstractInput implements AjaxTrigger, AjaxTarget, SubordinateTrigger, SubordinateTarget, Placeholderable, AutocompleteableText
A WTextField is a wcomponent used to display a html text input field. Use the method "getText" to get the text entered into the field by the user. Common configuration methods include "setColumns" and "setMaxlength".- Since:
- 1.0.0
- Author:
- James Gifford, Martin Shevchenko, Jonathan Austin, Mark Reeves
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWTextField.TextFieldModelTextFieldModel 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 WTextField()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAutocompleteSection(String sectionName)Pre-pend anautocompletesection to the value of anautocompleteattribute for the current field.voidclearAutocomplete()Clear theautocompleteattribute.protected booleandoHandleRequest(Request request)Override handleRequest in order to perform processing for this component.StringgetAutocomplete()intgetColumns()protected WTextField.TextFieldModelgetComponentModel()Returns the effective component model for this component.intgetMaxLength()intgetMinLength()protected WTextField.TextFieldModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.StringgetPattern()StringgetPlaceholder()Get the placeholder text, if explicitly set.StringgetRequestValue(Request request)Provide the value of the component on the Request.WSuggestionsgetSuggestions()StringgetText()Retrieves the text field's text.StringgetValue()Provide the value of the component returned byDataBound.getData()in the correct format.protected WTextField.TextFieldModelnewComponentModel()Creates a new TextFieldModel holds Extrinsic state management of the field.voidsetAddressAutocomplete(AddressType addressType, AddressPart addressPart)Set values for theautocompleteattribute applicable to an address or part thereof.voidsetAutocomplete(AutocompleteSegment value)Setautocompleteattribute value for a field based on a segment name.voidsetAutocomplete(DateType value)Set theautocompletes attribute for a type of date input.voidsetAutocomplete(Email value)Set theautocompleteattribute to a specific "email" value.voidsetAutocomplete(Numeric value)Set the autocomplete attribute for a number field for a given numeric auto-fill value.voidsetAutocomplete(Password value)Set theautocompleteattribute of a password field to a given password auto-fill hint type.voidsetAutocomplete(Telephone phone, PhoneFormat phoneType)Set theautocompleteattribute to an appropriate value for a particular type of phone number, in either of a full or local format.voidsetAutocomplete(Url value)Set theautocompleteattribute to a specific URL auto-fill type: "url", "impp" or "photo".protected voidsetAutocomplete(String autocompleteValue)Set the value of theautocompleteattribute for the current field.voidsetAutocompleteOff()Turnautocompleteoff for the current field.voidsetColumns(int columns)Sets the width of the input field more-or-less in characters.voidsetMaxLength(int maxLength)Set the maximum number of characters that the user can enter into the text field.voidsetMinLength(int minLength)Set the minimum number of characters that the user can enter into the text field.voidsetPattern(String pattern)The pattern to validate against.voidsetPhoneSegmentAutocomplete(PhoneFormat phoneType, PhonePart phoneSegment)Set theautocompleteattribute value relevant for a specified telephone number type and segment.voidsetPlaceholder(String placeholder)Set placeholder text which will appear in the field if it is editable and has no content.voidsetSuggestions(WSuggestions suggestions)Set theWSuggestionsfor this textfield.voidsetText(String text)Sets the text value to be shown in the input field for the given user.protected voidvalidateComponent(List<Diagnostic> diags)Override validateComponent to perform further validation.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractInput
addValidator, beforeHandleRequest, createMandatoryDiagnostic, doHandleChanged, getActionCommand, getActionObject, getActionOnChange, getDefaultSubmitButton, getDiagnostics, getValidators, getValueAsString, 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, 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.autocomplete.Autocompleteable
isAutocompleteOff
-
Methods inherited from interface com.github.bordertech.wcomponents.autocomplete.AutocompleteableDate
setBirthdayAutocomplete
-
Methods inherited from interface com.github.bordertech.wcomponents.autocomplete.AutocompleteableEmail
setEmailAutocomplete
-
Methods inherited from interface com.github.bordertech.wcomponents.autocomplete.AutocompleteablePhone
setFullPhoneAutocomplete, setFullPhoneAutocomplete, setLocalPhoneAutocomplete, setLocalPhoneAutocomplete
-
Methods inherited from interface com.github.bordertech.wcomponents.autocomplete.AutocompleteableURL
setUrlAutocomplete
-
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
-
doHandleRequest
protected boolean doHandleRequest(Request request)
Override handleRequest in order to perform processing for this component. This implementation updates the text field's text if it has changed.- Specified by:
doHandleRequestin classAbstractInput- Parameters:
request- the request being responded to.- Returns:
- true if the text field has changed, otherwise false
-
getRequestValue
public String 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:
getRequestValuein 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 String 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- Overrides:
getValuein classAbstractInput- Returns:
- the value of the component returned by
DataBound.getData()in the correct format.
-
getText
public String getText()
Retrieves the text field's text.- Returns:
- the text field's text.
-
setText
public void setText(String text)
Sets the text value to be shown in the input field for the given user.- Parameters:
text- the text to display for the given context.
-
setPlaceholder
public void setPlaceholder(String placeholder)
Set placeholder text which will appear in the field if it is editable and has no content.- Specified by:
setPlaceholderin interfacePlaceholderable- Parameters:
placeholder- The text to set as the placeholder.
-
getPlaceholder
public String getPlaceholder()
Get the placeholder text, if explicitly set.- Specified by:
getPlaceholderin interfacePlaceholderable- Returns:
- The placeholder text, if set.
-
getColumns
public int getColumns()
- Returns:
- the width of the input field in characters.
-
setColumns
public void setColumns(int columns)
Sets the width of the input field more-or-less in characters. The actual width of the input will vary from browser to browser bit will be in the region of 1.4 × columns.- Parameters:
columns- the number of characters to display.
-
getMinLength
public int getMinLength()
- Returns:
- the minimum number of characters that the user can enter into the text field.
-
setMinLength
public void setMinLength(int minLength)
Set the minimum number of characters that the user can enter into the text field.
Setting the minimum number of characters will not make a field mandatory as the validation is only applied once the user has entered some text. Use
AbstractInput.setMandatory(boolean)to make a field mandatory, which can be used in combination with setMinLength.- Parameters:
minLength- the minimum number of characters to allow.
-
getMaxLength
public int getMaxLength()
- Returns:
- the maximum number of characters that the user can enter into the text field.
-
setMaxLength
public final void setMaxLength(int maxLength)
Set the maximum number of characters that the user can enter into the text field.- Parameters:
maxLength- the maximum number of characters to allow.
-
setPattern
public final void setPattern(String pattern)
The pattern to validate against.The pattern must be supported natively by your target user agent (e.g. browser).
It is expected the
WLabelfor this component describes the required format of the component.- Parameters:
pattern- the pattern to validate against.
-
getPattern
public String getPattern()
- Returns:
- the pattern to validate against.
-
getSuggestions
public WSuggestions getSuggestions()
- Returns:
- the
WSuggestionsfor this textfield.
-
setSuggestions
public final void setSuggestions(WSuggestions suggestions)
Set theWSuggestionsfor this textfield.- Parameters:
suggestions- theWSuggestionsfor this textfield
-
validateComponent
protected void validateComponent(List<Diagnostic> diags)
Override validateComponent to perform further validation.- Overrides:
validateComponentin classAbstractInput- Parameters:
diags- the list into which any validation diagnostics are added.
-
newComponentModel
protected WTextField.TextFieldModel newComponentModel()
Creates a new TextFieldModel holds Extrinsic state management of the field.- Overrides:
newComponentModelin classAbstractInput- Returns:
- a new TextFieldModel
-
getComponentModel
protected WTextField.TextFieldModel 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 classAbstractInput- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WTextField.TextFieldModel 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 classAbstractInput- Returns:
- the model for this component
-
setAutocomplete
protected void setAutocomplete(String autocompleteValue)
Set the value of theautocompleteattribute for the current field.- Parameters:
autocompleteValue- the value to set as a (optionally space delimited list of) String value(s).
-
getAutocomplete
public String getAutocomplete()
- Specified by:
getAutocompletein interfaceAutocompleteable- Returns:
- the value of the
autocompleteattribute applied to the current field.
-
setAutocompleteOff
public void setAutocompleteOff()
Description copied from interface:AutocompleteableTurnautocompleteoff for the current field.- Specified by:
setAutocompleteOffin interfaceAutocompleteable
-
addAutocompleteSection
public void addAutocompleteSection(String sectionName)
Description copied from interface:AutocompleteablePre-pend anautocompletesection to the value of anautocompleteattribute for the current field.- Specified by:
addAutocompleteSectionin 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:AutocompleteableClear theautocompleteattribute.- Specified by:
clearAutocompletein interfaceAutocompleteable
-
setAutocomplete
public void setAutocomplete(DateType value)
Description copied from interface:AutocompleteableDateSet theautocompletes attribute for a type of date input.- Specified by:
setAutocompletein interfaceAutocompleteableDate- Parameters:
value- the type of date to auto-fill, currently only "bday" is supported.
-
setAutocomplete
public void setAutocomplete(Email value)
Description copied from interface:AutocompleteableEmailSet theautocompleteattribute to a specific "email" value. Currently only value "email" is supported.- Specified by:
setAutocompletein interfaceAutocompleteableEmail- Parameters:
value- the auto-fill hint value
-
setAutocomplete
public void setAutocomplete(Numeric value)
Description copied from interface:AutocompleteableNumericSet the autocomplete attribute for a number field for a given numeric auto-fill value.- Specified by:
setAutocompletein interfaceAutocompleteableNumeric- Parameters:
value- the type of number for auto-fill
-
setAutocomplete
public void setAutocomplete(Password value)
Description copied from interface:AutocompleteablePasswordSet theautocompleteattribute of a password field to a given password auto-fill hint type.- Specified by:
setAutocompletein interfaceAutocompleteablePassword- Parameters:
value- the type of password field to auto-fill
-
setAutocomplete
public void setAutocomplete(Url value)
Description copied from interface:AutocompleteableURLSet theautocompleteattribute to a specific URL auto-fill type: "url", "impp" or "photo".- Specified by:
setAutocompletein interfaceAutocompleteableURL- Parameters:
value- the auto-fill hint value
-
setAutocomplete
public void setAutocomplete(AutocompleteSegment value)
Description copied from interface:AutocompleteableTextSetautocompleteattribute value for a field based on a segment name.- Specified by:
setAutocompletein interfaceAutocompleteableText- Parameters:
value- the auto-fill mnemonic
-
setAutocomplete
public void setAutocomplete(Telephone phone, PhoneFormat phoneType)
Description copied from interface:AutocompleteablePhoneSet theautocompleteattribute to an appropriate value for a particular type of phone number, in either of a full or local format.- Specified by:
setAutocompletein interfaceAutocompleteablePhone- Parameters:
phone- the telephone auto-fill variant, being full (including international prefix) or local (without international prefix)phoneType- the type of phone to which the number belongs, for example "mobile" or "fax"
-
setPhoneSegmentAutocomplete
public void setPhoneSegmentAutocomplete(PhoneFormat phoneType, PhonePart phoneSegment)
Description copied from interface:AutocompleteableTextSet theautocompleteattribute value relevant for a specified telephone number type and segment.- Specified by:
setPhoneSegmentAutocompletein interfaceAutocompleteableText- Parameters:
phoneType- the type of phone numberphoneSegment- the phone number segment
-
setAddressAutocomplete
public void setAddressAutocomplete(AddressType addressType, AddressPart addressPart)
Description copied from interface:AutocompleteableTextSet values for theautocompleteattribute applicable to an address or part thereof.- Specified by:
setAddressAutocompletein interfaceAutocompleteableText- Parameters:
addressType- the type of address being auto-filledaddressPart- the address segment for the field
-
-