|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.control.AbstractControl org.apache.click.control.Field org.apache.click.control.TextField org.apache.click.extras.control.NumberField
public class NumberField
Provides a Number Field control: <input type='text'>.
Number Field |
NumberFormat
to format, parse and validate the
input text. The number format can either directly be set through
setNumberFormat(NumberFormat)
or by setting the number format
pattern with setPattern(String)
.
When NumberField is validated and the input string can be parsed by the
NumberFormat then the string value of this field
(@link org.apache.click.control.Field#getValue()} is set to the formatted value
of the input.
For example if you define an integer pattern of "#,##0" and the
users enters "2.54" then the resulting Number is 3. For all such cases the
NumberFormat does recognize the input as valid and does not mark the
field as invalid.
To get the exact string the user entered either turn validation
off or call Field.getValue()
.
When the Number is set through setNumber(Number)
the value of the field
is also set to the formatted number. The number returned from
getNumber()
is then the formatted number. It is not the original Number
passed in. To circumvent formatting use setValue().
<html> <head> $headElements </head> <body> $form $jsElements </body> </html>The NumberField has right justified horizontal text alignment,
Field.setTextAlign(String)
.
See also W3C HTML reference
INPUT
Field Summary | |
---|---|
protected double |
maxvalue
The maximum field value. |
protected double |
minvalue
The minimum field value. |
protected NumberFormat |
numberFormat
The NumberFormat for formatting the output. |
protected String |
pattern
The decimal pattern to use for a NumberFormat. |
protected static String |
VALIDATE_NUMBER_FIELD_FUNCTION
The field validation JavaScript function template. |
Fields inherited from class org.apache.click.control.TextField |
---|
maxLength, minLength, size, VALIDATE_TEXTFIELD_FUNCTION |
Fields inherited from class org.apache.click.control.Field |
---|
disabled, error, focus, form, help, label, labelStyle, labelStyleClass, parentStyleClassHint, parentStyleHint, readonly, required, tabindex, title, trim, validate, value |
Fields inherited from class org.apache.click.control.AbstractControl |
---|
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface org.apache.click.Control |
---|
CONTROL_MESSAGES |
Constructor Summary | |
---|---|
NumberField()
Create a NumberField with no name defined. |
|
NumberField(String name)
Construct a NumberField with the given name. |
|
NumberField(String name,
boolean required)
Construct a NumberField with the given name and required status. |
|
NumberField(String name,
String label)
Construct a NumberField with the given name and label. |
|
NumberField(String name,
String label,
boolean required)
Construct a NumberField with the given name, label and required status. |
|
NumberField(String name,
String label,
int size)
Construct the NumberField with the given name, label and size. |
|
NumberField(String name,
String label,
int size,
boolean required)
Construct the NumberField with the given name, label, size and required status. |
Method Summary | |
---|---|
List<Element> |
getHeadElements()
Returns the NumberField HTML HEAD elements for the click/extras-control.js resource. |
double |
getMaxValue()
Return the maximum valid double field value. |
double |
getMinValue()
Return the minimum valid double field value. |
Number |
getNumber()
Return the field Number value, or null if value was empty or a parsing error occurred. |
NumberFormat |
getNumberFormat()
Return the NumberFormat for formatting/parsing the field value. |
String |
getPattern()
Return the number pattern used for formatting and parsing. |
String |
getValidationJavaScript()
Return the field JavaScript client side validation function. |
Object |
getValueObject()
Return the field Number value, or null if value was empty or a parsing error occurred. |
void |
setMaxValue(double value)
Set the maximum valid double field value. |
void |
setMinValue(double value)
Set the minimum valid double field value. |
void |
setNumber(Number number)
Set the Number value of the field. |
void |
setNumberFormat(NumberFormat format)
Set the NumberFormat for this field. |
void |
setPattern(String pattern)
Set the number pattern used for formatting and parsing. |
void |
setValueObject(Object object)
Set the Number value of the field using the given object. |
void |
validate()
Validates the NumberField request submission. |
Methods inherited from class org.apache.click.control.TextField |
---|
getControlSizeEst, getMaxLength, getMinLength, getSize, getTag, getType, render, setMaxLength, setMinLength, setSize |
Methods inherited from class org.apache.click.control.Field |
---|
bindRequestValue, getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getState, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, onProcess, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setValue, setWidth |
Methods inherited from class org.apache.click.control.AbstractControl |
---|
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final String VALIDATE_NUMBER_FIELD_FUNCTION
protected double maxvalue
protected double minvalue
protected NumberFormat numberFormat
protected String pattern
Constructor Detail |
---|
public NumberField(String name)
name
- the name of the fieldpublic NumberField(String name, String label)
name
- the name of the fieldlabel
- the label of the fieldpublic NumberField(String name, boolean required)
name
- the name of the fieldrequired
- the field required statuspublic NumberField(String name, String label, boolean required)
name
- the name of the fieldlabel
- the label of the fieldrequired
- the field required statuspublic NumberField(String name, String label, int size)
name
- the name of the fieldlabel
- the label of the fieldsize
- the size of the fieldpublic NumberField(String name, String label, int size, boolean required)
name
- the name of the fieldlabel
- the label of the fieldsize
- the size of the fieldrequired
- the field required statuspublic NumberField()
Method Detail |
---|
public double getMaxValue()
public void setMaxValue(double value)
value
- the maximum valid double field valuepublic void setMinValue(double value)
value
- the minimum valid double field valuepublic double getMinValue()
public Number getNumber()
public void setNumber(Number number)
number
- the field number value to setpublic NumberFormat getNumberFormat()
pattern
is applied to it.
This method is used through-out this class to obtain the NumberFormat.
By overriding this method full control is given onto which
NumberFormat is used for formatting, parsing and validating.
public void setNumberFormat(NumberFormat format)
pattern
is set. If the getPattern()
is set then
the pattern will be applied to the new Format if it a DecimalFormat.
format
- the number formatpublic String getPattern()
public void setPattern(String pattern)
pattern
- the pattern used for formatting and parsingpublic Object getValueObject()
getValueObject
in class Field
public void setValueObject(Object object)
setValueObject
in class Field
object
- the object value to setpublic List<Element> getHeadElements()
getHeadElements
in interface Control
getHeadElements
in class AbstractControl
Control.getHeadElements()
public String getValidationJavaScript()
getValidationJavaScript
in class TextField
public void validate()
Field.getValue()
) is
set to the formatted value of the user input.
A field error message is displayed if a validation error occurs.
These messages are defined in the resource bundle:
- /click-control.properties
- field-required-error
- number-format-error
- number-maxvalue-error
- number-minvalue-error
validate
in class TextField
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |