org.apache.wicket.markup.html.form
Class NumberTextField<N extends Number & Comparable<N>>

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
                  extended by org.apache.wicket.markup.html.form.FormComponent<T>
                      extended by org.apache.wicket.markup.html.form.AbstractTextComponent<T>
                          extended by org.apache.wicket.markup.html.form.TextField<N>
                              extended by org.apache.wicket.markup.html.form.NumberTextField<N>
Type Parameters:
N - the type of the number
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IConverterLocator, IGenericComponent<N>, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
RangeTextField

public class NumberTextField<N extends Number & Comparable<N>>
extends TextField<N>

A TextField for HTML5 <input> with type number.

Automatically validates the input against the configured min and max attributes. If any of them is null then respective MIN_VALUE or MAX_VALUE for the number type is used. If the number type has no minimum and/or maximum value then Double.MIN_VALUE and Double.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 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_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
NumberTextField(String id)
          Construct.
NumberTextField(String id, IModel<N> model)
          Construct.
NumberTextField(String id, IModel<N> model, Class<N> type)
          Construct.
 
Method Summary
protected  void convertInput()
          Always use Locale.ENGLISH to parse the input.
protected  String getInputType()
          Subclass should override this method if this textfield is mapped on a different input type as text.
protected  String getModelValue()
          The formatting for Locale.ENGLISH might not be compatible with HTML (e.g.
protected  void onComponentTag(ComponentTag tag)
          Processes the component tag.
 void onConfigure()
          Called once per request on components before they are about to be rendered.
 NumberTextField<N> setMaximum(N maximum)
          Sets the maximum allowed value
 NumberTextField<N> setMinimum(N minimum)
          Sets the minimum allowed value
 NumberTextField<N> setStep(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, getModel, getModelObject, 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, setModel, setModelObject, setModelValue, setRequired, setType, shouldTrimInput, trim, 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
getWebPage, getWebRequest, getWebResponse, getWebSession
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, 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, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onEvent, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberTextField

public NumberTextField(String id)
Construct.

Parameters:
id - component id

NumberTextField

public NumberTextField(String id,
                       IModel<N> model)
Construct.

Parameters:
id - component id
model - the input value

NumberTextField

public NumberTextField(String id,
                       IModel<N> model,
                       Class<N> type)
Construct.

Parameters:
id - component id
model - the input value
type - The type to use when updating the model for this text field
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

onConfigure

public void onConfigure()
Description copied from class: Component
Called once per request on components before they are about to be rendered. This method should be used to configure such things as visibility and enabled flags.

Overrides must call super.onConfigure(), usually before any other code

NOTE: 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() and Component.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 by other.isVisible() as mentioned in Component.configure() javadoc.

NOTE: Why should Component.onBeforeRender() not be used for this? Because if a component's visibility is controlled inside Component.onBeforeRender(), once invisible the component will never become visible again.

Overrides:
onConfigure in class Component

onComponentTag

protected void onComponentTag(ComponentTag tag)
Description copied from class: TextField
Processes the component tag.

Overrides:
onComponentTag in class TextField<N extends Number & Comparable<N>>
Parameters:
tag - Tag to modify
See Also:
Component.onComponentTag(ComponentTag)

getInputType

protected String getInputType()
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:
getInputType in class TextField<N extends Number & Comparable<N>>
Returns:
The input type of this textfield, default is null

getModelValue

protected String getModelValue()
The formatting for Locale.ENGLISH might not be compatible with HTML (e.g. group digits), thus use Objects.stringValue(Object) instead.

Overrides:
getModelValue in class FormComponent<N extends Number & Comparable<N>>
Returns:
value

convertInput

protected void convertInput()
Always use Locale.ENGLISH to parse the input.

Overrides:
convertInput in class AbstractTextComponent<N extends Number & Comparable<N>>
See Also:
FormComponent.convertInput()


Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.