Class NumberTextField<N extends Number & Comparable<N>>
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
-
- org.apache.wicket.markup.html.form.FormComponent<T>
-
- org.apache.wicket.markup.html.form.AbstractTextComponent<T>
-
- org.apache.wicket.markup.html.form.TextField<N>
-
- org.apache.wicket.markup.html.form.NumberTextField<N>
-
- Type Parameters:
N
- the type of the number
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IGenericComponent<N,FormComponent<N>>
,IMetadataContext<Serializable,Component>
,IFormModelUpdateListener
,IFormVisitorParticipant
,ILabelProvider<String>
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
RangeTextField
public class NumberTextField<N extends Number & Comparable<N>> extends TextField<N>
ATextField
for HTML5 <input> with type number.The
<input>
's value will be rendered in floating-point representation, as required by the HTML specification. Use a simpleTextField
to use a locale specific conversion of numbers.Automatically validates the input against the configured
min
andmax
attributes. If any of them isnull
then respective MIN_VALUE or MAX_VALUE for the number type is used. If the number type has no minimum and/or maximum value thenDouble.MIN_VALUE
andDouble.MAX_VALUE
are used respectfully.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.wicket.markup.html.form.AbstractTextComponent
AbstractTextComponent.ITextFormatProvider
-
-
Field Summary
Fields Modifier and Type Field Description static Double
ANY
Use this as a marker of step attribute value "any" Because the w3c spec requires step to be a non-negative digit greater than zero we use zero as delegate for "any" keyword.-
Fields inherited from class org.apache.wicket.markup.html.form.FormComponent
FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL, VALUE_SEPARATOR
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Constructor Summary
Constructors Constructor Description NumberTextField(String id)
Construct.NumberTextField(String id, Class<N> type)
Construct.NumberTextField(String id, IModel<N> model)
Construct.NumberTextField(String id, IModel<N> model, Class<N> type)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
convertInput()
Always useLocale.ENGLISH
to parse the input.protected String[]
getInputTypes()
Subclass should override this method if this textfield is mapped on a different input type as text.protected String
getModelValue()
The formatting forLocale.ENGLISH
might not be compatible with HTML (e.g.protected void
onComponentTag(ComponentTag tag)
Processes the component tag.protected void
onConfigure()
Called on all components before any component is rendered.NumberTextField<N>
setMaximum(N maximum)
Sets the maximum allowed valueNumberTextField<N>
setMaximum(IModel<N> maximum)
Sets the maximum allowed valueNumberTextField<N>
setMinimum(N minimum)
Sets the minimum allowed valueNumberTextField<N>
setMinimum(IModel<N> minimum)
Sets the minimum allowed valueNumberTextField<N>
setStep(N step)
Sets the step attributeNumberTextField<N>
setStep(IModel<N> step)
Sets the step attribute-
Methods inherited from class org.apache.wicket.markup.html.form.AbstractTextComponent
getConvertEmptyInputStringToNull, isInputNullable, onBeforeRender, setConvertEmptyInputStringToNull
-
Methods inherited from class org.apache.wicket.markup.html.form.FormComponent
add, add, checkRequired, clearInput, convertValue, error, getConvertedInput, getDefaultLabel, getDefaultLabel, getForm, getInput, getInputAsArray, getInputName, getParameterValues, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isMultiPart, isRequired, isValid, newValidatable, newValidationError, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, remove, reportRequiredError, setConvertedInput, setLabel, setModelValue, setRequired, setType, shouldTrimInput, trim, updateAutoLabels, updateCollectionModel, updateModel, valid, validate, validateRequired, validateValidators, visitComponentsPostOrder, visitFormComponentsPostOrder
-
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
getLabel
-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IGenericComponent
getDefaultModel, getDefaultModelObject, getModel, getModelObject, setDefaultModel, setDefaultModelObject, setModel, setModelObject
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
NumberTextField
public NumberTextField(String id)
Construct.- Parameters:
id
- The component id
-
NumberTextField
public NumberTextField(String id, Class<N> type)
Construct.- Parameters:
id
- The component idtype
- The type to use when updating the model for this text field
-
NumberTextField
public NumberTextField(String id, IModel<N> model)
Construct.- Parameters:
id
- The component idmodel
- The input value
-
-
Method Detail
-
setMinimum
public NumberTextField<N> setMinimum(N minimum)
Sets the minimum allowed value- Parameters:
minimum
- the minimum allowed value- Returns:
- this instance
-
setMaximum
public NumberTextField<N> setMaximum(N maximum)
Sets the maximum allowed value- Parameters:
maximum
- the maximum allowed value- Returns:
- this instance
-
setStep
public NumberTextField<N> setStep(N step)
Sets the step attribute- Parameters:
step
- the step attribute- Returns:
- this instance
-
setMinimum
public NumberTextField<N> setMinimum(IModel<N> minimum)
Sets the minimum allowed value- Parameters:
minimum
- the minimum allowed value- Returns:
- this instance
-
setMaximum
public NumberTextField<N> setMaximum(IModel<N> maximum)
Sets the maximum allowed value- Parameters:
maximum
- the maximum allowed value- Returns:
- this instance
-
setStep
public NumberTextField<N> setStep(IModel<N> step)
Sets the step attribute- Parameters:
step
- the step attribute- Returns:
- this instance
-
onConfigure
protected void onConfigure()
Description copied from class:Component
Called on all components before any component is rendered. This method should be used to configure such things as visibility and enabled flags.Overrides must call
super.onConfigure()
, usually before any other codeNOTE: Component hierarchy should not be modified inside this method, instead it should be done in
Component.onBeforeRender()
NOTE: Why this method is preferrable to directly overriding
Component.isVisible()
andComponent.isEnabled()
? Because those methods are called multiple times even for processing of a single request. If they contain expensive logic they can slow down the response time of the entire page. Further, overriding those methods directly on form components may lead to inconsistent or unexpected state depending on when those methods are called in the form processing workflow. It is a better practice to push changes to state rather than pull.NOTE: If component's visibility or another property depends on another component you may call
other.configure()
followed byother.isVisible()
as mentioned inComponent.configure()
javadoc.NOTE: Why should
Component.onBeforeRender()
not be used for this? Because if a component's visibility is controlled insideComponent.onBeforeRender()
, once invisible the component will never become visible again.- Overrides:
onConfigure
in classComponent
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Description copied from class:TextField
Processes the component tag.- Overrides:
onComponentTag
in classTextField<N extends Number & Comparable<N>>
- Parameters:
tag
- Tag to modify- See Also:
Component.onComponentTag(ComponentTag)
-
getInputTypes
protected String[] getInputTypes()
Description copied from class:TextField
Subclass should override this method if this textfield is mapped on a different input type as text. Like PasswordTextField or HiddenField.- Overrides:
getInputTypes
in classTextField<N extends Number & Comparable<N>>
- Returns:
- The input type of this textfield, default is null
-
getModelValue
protected String getModelValue()
The formatting forLocale.ENGLISH
might not be compatible with HTML (e.g. group digits), thus useObjects.stringValue(Object)
instead.- Overrides:
getModelValue
in classFormComponent<N extends Number & Comparable<N>>
- Returns:
- value
-
convertInput
public void convertInput()
Always useLocale.ENGLISH
to parse the input.- Overrides:
convertInput
in classAbstractTextComponent<N extends Number & Comparable<N>>
- See Also:
FormComponent.convertInput()
-
-