Class WMultiTextField
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WMultiTextField
-
- All Implemented Interfaces:
AjaxTarget
,AjaxTrigger
,BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Diagnosable
,Disableable
,Input
,Labelable
,Mandatable
,MultiInputComponent
,Placeholderable
,SubordinateTarget
,WComponent
,WebComponent
,Serializable
public class WMultiTextField extends AbstractInput implements AjaxTrigger, AjaxTarget, SubordinateTarget, MultiInputComponent, Placeholderable
The WMultiTextField component allows multiple text input elements to be generated dynamically on the client without requiring the page to be reloaded. This component takes its appearance and attributes from a regular text input but allows for one or more items of text to be entered via the add link adjacent to the right of the text input.
This component is useful in instances where the user needs to enter one or more text items into the interfaces for a particular field. For instance, the user may have one or more aliases that need to be entered into the system.
The following attributes can be set on WMultiTextField:
- MaxInputs: The maximum number of text inputs the user can add to the component. Client-side functionality will stop users adding more than the allowable number of inputs via the UI. This class chops off any excess inputs if an attempt is made to add them programmatically.
- MaxLength: The maximum length of the text fields rendered to allow user text entry.
- Columns: The size of the text fields rendered to allow user text entry.
- Since:
- 1.0.0
- Author:
- Christina Harris, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WMultiTextField.MultiTextFieldModel
MultiTextFieldModel 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 WMultiTextField()
Creates an empty WMultiTextField.WMultiTextField(String[] inputs)
Creates a WMultiTextField with the default input values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
doHandleRequest(Request request)
Set the inputs based on the incoming request.int
getColumns()
protected WMultiTextField.MultiTextFieldModel
getComponentModel()
Returns the effective component model for this component.int
getMaxInputs()
int
getMaxLength()
int
getMinLength()
protected WMultiTextField.MultiTextFieldModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.String
getPattern()
String
getPlaceholder()
Get the placeholder text, if explicitly set.String[]
getRequestValue(Request request)
Provide the value of the component on the Request.String[]
getTextInputs()
String[]
getValue()
Provide the value of the component returned byDataBound.getData()
in the correct format.String
getValueAsString()
The string is a comma seperated list of the string inputs.protected WMultiTextField.MultiTextFieldModel
newComponentModel()
Creates a new MultiTextFieldModel holds Extrinsic state management of the field.void
setColumns(int columns)
Sets the width of the input field in characters.void
setData(Object data)
Sets the data that this component displays/edits.void
setMaxInputs(int max)
Set the maximum number of strings/inputs that can be associated to this component.void
setMaxLength(int maxLength)
Set the maximum number of characters that the user can enter into the multi text field.void
setMinLength(int minLength)
Set the minimum number of characters that the user can enter into the multi text field.void
setPattern(String pattern)
The pattern to validate against.void
setPlaceholder(String placeholder)
Set placeholder text which will appear in the field if it is editable and has no content.void
setTextInputs(String[] inputs)
Set the text inputs of this component.protected void
validateComponent(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, 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.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
-
WMultiTextField
public WMultiTextField()
Creates an empty WMultiTextField.
-
WMultiTextField
public WMultiTextField(String[] inputs)
Creates a WMultiTextField with the default input values.- Parameters:
inputs
- the default set of values.
-
-
Method Detail
-
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:
getValue
in interfaceInput
- Overrides:
getValue
in classAbstractInput
- Returns:
- the value of the component returned by
DataBound.getData()
in the correct format.
-
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
-
getTextInputs
public String[] getTextInputs()
- Returns:
- The text inputs of this component.
-
setTextInputs
public void setTextInputs(String[] inputs)
Set the text inputs of this component.- Parameters:
inputs
- The text inputs to set.
-
getMaxInputs
public int getMaxInputs()
- Returns:
- The maximum number of strings that can be associated to this component.
-
setMaxInputs
public void setMaxInputs(int max)
Set the maximum number of strings/inputs that can be associated to this component.- Parameters:
max
- The maximum number of text inputs.
-
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 in characters.- 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 multi text field.
-
setMinLength
public final void setMinLength(int minLength)
Set the minimum number of characters that the user can enter into the multi 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 multi text field.
-
setMaxLength
public final void setMaxLength(int maxLength)
Set the maximum number of characters that the user can enter into the multi 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
WLabel
for 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.
-
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:
setPlaceholder
in interfacePlaceholderable
- Parameters:
placeholder
- The text to set as the placeholder.
-
getPlaceholder
public String getPlaceholder()
Get the placeholder text, if explicitly set.- Specified by:
getPlaceholder
in interfacePlaceholderable
- Returns:
- The placeholder text, if set.
-
getValueAsString
public String getValueAsString()
The string is a comma seperated list of the string inputs.- Specified by:
getValueAsString
in interfaceInput
- Overrides:
getValueAsString
in classAbstractInput
- Returns:
- A string concatenation of the string inputs.
-
doHandleRequest
protected boolean doHandleRequest(Request request)
Set the inputs based on the incoming request. The text input values are set as an array of strings on the parameter with this nameAbstractWComponent.getName()
. Any empty strings will be ignored.- Specified by:
doHandleRequest
in classAbstractInput
- Parameters:
request
- the current request.- Returns:
- true if the inputs have changed, otherwise return 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:
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.
-
validateComponent
protected void validateComponent(List<Diagnostic> diags)
Override validateComponent to perform further validation.- Overrides:
validateComponent
in classAbstractInput
- Parameters:
diags
- the list into which any validation diagnostics are added.
-
newComponentModel
protected WMultiTextField.MultiTextFieldModel newComponentModel()
Creates a new MultiTextFieldModel holds Extrinsic state management of the field.- Overrides:
newComponentModel
in classAbstractInput
- Returns:
- a new MultiTextFieldModel
-
getComponentModel
protected WMultiTextField.MultiTextFieldModel 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 WMultiTextField.MultiTextFieldModel 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
-
-