Class NumberTextField<N extends java.lang.Number & java.lang.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:
java.io.Serializable,java.lang.Iterable<Component>,IEventSink,IEventSource,IFeedbackContributor,IConverterLocator,IGenericComponent<N,FormComponent<N>>,IMetadataContext<java.io.Serializable,Component>,IFormModelUpdateListener,IFormVisitorParticipant,ILabelProvider<java.lang.String>,IHeaderContributor,IRequestableComponent,org.apache.wicket.util.IHierarchical<Component>,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
RangeTextField
public class NumberTextField<N extends java.lang.Number & java.lang.Comparable<N>> extends TextField<N>
ATextFieldfor HTML5 <input> with type number.The
<input>'s value will be rendered in floating-point representation, as required by the HTML specification. Use a simpleTextFieldto use a locale specific conversion of numbers.Automatically validates the input against the configured
minandmaxattributes. If any of them isnullthen 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_VALUEandDouble.MAX_VALUEare 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 java.lang.DoubleANYUse 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
-
-
Constructor Summary
Constructors Constructor Description NumberTextField(java.lang.String id)Construct.NumberTextField(java.lang.String id, java.lang.Class<N> type)Construct.NumberTextField(java.lang.String id, IModel<N> model)Construct.NumberTextField(java.lang.String id, IModel<N> model, java.lang.Class<N> type)Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconvertInput()Always useLocale.ENGLISHto parse the input.protected java.lang.String[]getInputTypes()Subclass should override this method if this textfield is mapped on a different input type as text.protected java.lang.StringgetModelValue()The formatting forLocale.ENGLISHmight not be compatible with HTML (e.g.protected voidonComponentTag(ComponentTag tag)Processes the component tag.protected voidonConfigure()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, 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, 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, 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
-
-
-
-
Constructor Detail
-
NumberTextField
public NumberTextField(java.lang.String id)
Construct.- Parameters:
id- The component id
-
NumberTextField
public NumberTextField(java.lang.String id, java.lang.Class<N> type)Construct.- Parameters:
id- The component idtype- The type to use when updating the model for this text field
-
NumberTextField
public NumberTextField(java.lang.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:ComponentCalled 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:
onConfigurein classComponent
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Description copied from class:TextFieldProcesses the component tag.- Overrides:
onComponentTagin classTextField<N extends java.lang.Number & java.lang.Comparable<N>>- Parameters:
tag- Tag to modify- See Also:
Component.onComponentTag(ComponentTag)
-
getInputTypes
protected java.lang.String[] getInputTypes()
Description copied from class:TextFieldSubclass should override this method if this textfield is mapped on a different input type as text. Like PasswordTextField or HiddenField.- Overrides:
getInputTypesin classTextField<N extends java.lang.Number & java.lang.Comparable<N>>- Returns:
- The input type of this textfield, default is null
-
getModelValue
protected java.lang.String getModelValue()
The formatting forLocale.ENGLISHmight not be compatible with HTML (e.g. group digits), thus useObjects.stringValue(Object)instead.- Overrides:
getModelValuein classFormComponent<N extends java.lang.Number & java.lang.Comparable<N>>- Returns:
- value
-
convertInput
public void convertInput()
Always useLocale.ENGLISHto parse the input.- Overrides:
convertInputin classAbstractTextComponent<N extends java.lang.Number & java.lang.Comparable<N>>- See Also:
FormComponent.convertInput()
-
-