org.apache.wicket.markup.html.form
Class NumberTextField<N extends java.lang.Number & java.lang.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 number type
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Component>, IEventSink, IEventSource, IClusterable, IConverterLocator, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider<java.lang.String>, IHeaderContributor, IRequestableComponent, IHierarchical<Component>
Direct Known Subclasses:
RangeTextField

public class NumberTextField<N extends java.lang.Number & java.lang.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 Double.MIN_VALUE and Double.MAX_VALUE are used respectfully. Note: FormComponent.setType(Class) must be called explicitly!

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(java.lang.String id)
          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
protected  java.lang.String getInputType()
          Subclass should override this method if this textfield is mapped on a different input type as text.
 java.util.Locale getLocale()
          Gets the locale for this component.
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
 
Methods inherited from class org.apache.wicket.markup.html.form.AbstractTextComponent
convertInput, 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, getModelValue, getRawInput, getType, getValidatorKeyPrefix, getValidators, getValue, hasRawInput, inputAsInt, inputAsInt, inputAsIntArray, inputChanged, internalOnModelChanged, invalid, isMultiPart, isRequired, isValid, newValidatable, onDetach, onDisabled, onInvalid, onValid, processChildren, processInput, remove, 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, setLabelInternal
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, hasAssociatedMarkup, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onMarkupAttached, 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, 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, getFeedbackMessage, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, 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, locateMarkupStream, 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, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberTextField

public NumberTextField(java.lang.String id)
Construct.

Parameters:
id - component id

NumberTextField

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

Parameters:
id - component id
model - the input value

NumberTextField

public NumberTextField(java.lang.String id,
                       IModel<N> model,
                       java.lang.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

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 visibility of a component is toggled inside Component.onBeforeRender() another method needs to be overridden to make sure Component.onBeforeRender() will be invoked on invisible components:

 class MyComponent extends WebComponent
 {
        protected void onBeforeRender()
        {
                setVisible(Math.rand() > 0.5f);
                super.onBeforeRender();
        }
 
        // if this override is forgotten, once invisible component will never become visible
        protected boolean callOnBeforeRenderIfNotVisible()
        {
                return true;
        }
 }
 
VS
 class MyComponent extends WebComponent
 {
        protected void onConfigure()
        {
                super.onConfigure();
                setVisible(Math.rand() > 0.5f);
        }
 }
 

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 java.lang.Number & java.lang.Comparable<N>>
Parameters:
tag - Tag to modify
See Also:
Component.onComponentTag(ComponentTag)

getInputType

protected java.lang.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 java.lang.Number & java.lang.Comparable<N>>
Returns:
The input type of this textfield, default is null

getLocale

public java.util.Locale getLocale()
Gets the locale for this component. By default, it searches its parents for a locale. If no parents (it's a recursive search) returns a locale, it gets one from the session. WICKET-3591 Browsers support only formatting in English

Overrides:
getLocale in class Component
Returns:
The locale to be used for this component
See Also:
Session.getLocale()


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