Class AbstractText
java.lang.Object
fc.web.forms.Field
fc.web.forms.AbstractText
- Direct Known Subclasses:
MaxSizable, TextArea
Represents a field that:
- returns one (1) string as their value. Contrast this with selects/with/multiple and radiogroups that may return a String[].
- In addition, the name of this field is always returned on a form submit by the browser (barring browser hacks etc). For example, if a text field is not filled out by the user, the browser still returns that text field (with no value). Contrast this with radio buttons that are not returned at all (not even their name) if the user does not select them.
Important note: the trimValues(boolean) method
will by default trim whitespace from the beginning/end of
user input. If the resulting string is empty (""), then
it will be treated as if the user had not entered anything.
(which is typically the desired behavior).
-
Nested Class Summary
Nested classes/interfaces inherited from class Field
Field.Type -
Method Summary
Modifier and TypeMethodDescriptionbooleanConvenience method that returns the value of this field as a boolean.doubleConvenience method that returns the value of this field as a Double.floatConvenience method that returns the value of this field as a Float.intgetIntValue(FormData fd) Convenience method that returns the value of this field as a Integer.shortConvenience method that returns the value of this field as a Short.Convenience method that returns the value of this field as a String.Returns a string representing the value of this field or null if there is no current value.booleanReturns true if this field was isFilled out or selected by the user, false otherwise.voidvoidSets the selected values for this select in the specified form data.voidSets the initial value of this text element to the specified string.voidsetValueFromSubmit(FormData fd, jakarta.servlet.http.HttpServletRequest req) Sets the value of the field from the submitted form data.toString()voidtrimValues(boolean val) Trims leading and ending spaces from all entered values.Methods inherited from class Field
add, addError, addLabel, addString, disable, disable, enable, enable, getLabel, getName, getType, getValidateErrors, isEnabled, render, render, render, renderError, renderError, renderImpl, renderStyleTag, setStyleTag, validate
-
Method Details
-
setValueFromSubmit
public void setValueFromSubmit(FormData fd, jakarta.servlet.http.HttpServletRequest req) throws SubmitHackedException Sets the value of the field from the submitted form data. Note, by default, it is assumed that all abstract text fields have different names in the html form. Mulitple fields with the same name are not supported. If there is more than one field with the same name (such as multiple text fields with the same name), then only 1 value will be saved (and the rest will be ignored) [This is one of - or perhaps the only - restriction of this form API; without it, things become too complex to manage].- Specified by:
setValueFromSubmitin classField- Parameters:
fd- the form data object to store the value in- Throws:
SubmitHackedException
-
setValue
-
setValue
Sets the selected values for this select in the specified form data. This is useful for showing different initial values to each user (before the form has been submitted by that user).If the form has not been submitted, there is no form data object. A form data object should be manually created if needed for storing the value.
- Parameters:
fd- the non-null form data used for rendering the formvalue- the value to be set
-
getValue
Returns a string representing the value of this field or null if there is no current value. The names of Form fields like text and textarea are always sent back by the browser if the field is enabled. However if the values are empty, then this method will return null. For example, if the browser returnedfoo=invalid input: '&bar'=baz , then foo will have a null value (even though the servlet api returns an empty string). -
getStringValue
Convenience method that returns the value of this field as a String. null values (ie which can happen when the field is disabled and no value sent by the browser) are returned as an empty string.- Throws:
NumberFormatException- if the value could not be returned as in integer.
-
getIntValue
Convenience method that returns the value of this field as a Integer.- Throws:
NumberFormatException- if the value could not be returned as an integer.
-
getShortValue
Convenience method that returns the value of this field as a Short.- Throws:
NumberFormatException- if the value could not be returned as a short.
-
getFloatValue
Convenience method that returns the value of this field as a Float.- Throws:
NumberFormatException- if the value could not be returned as a float.
-
getDoubleValue
Convenience method that returns the value of this field as a Double.- Throws:
NumberFormatException- if the value could not be returned as a double.
-
getBooleanValue
Convenience method that returns the value of this field as a boolean. The value is converted into a boolean as per the invalid input: '{@link Boolean.valueOf(String)'} method. -
isFilled
Description copied from class:FieldReturns true if this field was isFilled out or selected by the user, false otherwise.Note: Some fields like selects will never be empty since non-multiple select fields always send their default selected value. [although select/with/multiple can be empty since the browser sends (much like radio buttoms) nothing at all when no option is selected].
-
reset
-
trimValues
Trims leading and ending spaces from all entered values. This is true by default. Specify false to turn this off. -
toString
-