|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.control.AbstractControl net.sf.click.control.Field net.sf.click.control.TextField net.sf.click.extras.control.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 net.sf.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 formated number. The number returned from
getNumber()
is then the formatted number. It is not the orginal Number
passed in. To circumvent formatting use setValue().
The NumberField uses a JavaScript onkeypress() doubleFilter() method to prevent
users from entering invalid characters. To enable number key filtering
reference $jsImports and $cssImports in your page
template. For example:
<html> <head> $cssImports </head> <body> $form </body> </html> $jsImportsThe NumberField has right justified horizontal text alignment,
Field.setTextAlign(String)
.
See also W3C HTML reference
INPUT
Field Summary | |
static String |
HTML_IMPORTS
The NumberField.js imports statement. |
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 net.sf.click.control.TextField |
maxLength, minLength, size, VALIDATE_TEXTFIELD_FUNCTION |
Fields inherited from class net.sf.click.control.Field |
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value |
Fields inherited from class net.sf.click.control.AbstractControl |
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface net.sf.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 | |
String |
getHtmlImports()
Return the HTML head import statements for the JavaScript (click/extras-control.js) file. |
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 occured. |
NumberFormat |
getNumberFormat()
Return the NumberFormat for formating/parsing the field value. |
String |
getPattern()
Return the number pattern used for formatting and parsing. |
protected String |
getRequestValue()
|
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 occured. |
void |
onDeploy(ServletContext servletContext)
Deploy the extras-control.js file to the click web directory when the application is initialized. |
void |
setMaxValue(double value)
Set the maximum valid double field value. |
void |
setMinValue(double value)
Set the miminum 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 net.sf.click.control.TextField |
getControlSizeEst, getMaxLength, getMinLength, getSize, getTag, getType, render, setMaxLength, setMinLength, setSize |
Methods inherited from class net.sf.click.control.Field |
bindRequestValue, getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setWidth |
Methods inherited from class net.sf.click.control.AbstractControl |
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDestroy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, 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
public static final String HTML_IMPORTS
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 miminum 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()
public void setValueObject(Object object)
object
- the object value to setpublic String getHtmlImports()
Control.getHtmlImports()
public String getValidationJavaScript()
public void onDeploy(ServletContext servletContext)
servletContext
- the servlet contextControl.onDeploy(ServletContext)
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
protected String getRequestValue()
Field.getRequestValue()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |