Class DependentSelect
java.lang.Object
fc.web.forms.Field
fc.web.forms.DependentField
fc.web.forms.DependentSelect
A dependent HTML DependentSelect field. The values of this field change based
on the chosen value of some other field in the form. These new values are
calculated/set on the server side.
Another good (and equally valid) approach is to instead use javascript arrays (with different sets of values) and swap out values on the client and/or use AJAX on the client side.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class Field
Field.Type -
Constructor Summary
ConstructorsConstructorDescriptionDependentSelect(String name) Creates a new select element with no initial values. -
Method Summary
Modifier and TypeMethodDescriptionallowMultiple(FormData fd, boolean allow) true if multiple selections are allowed, false otherwise.booleanConvenience method that returns the single value of this field as a boolean.intgetIntValue(FormData fd) Convenience method that returns the single value of this field as a Integer.Convenience method that returns the selected option as a String.getType()Subclasses should return an appropriateField.Type.Returns a List containing the selected options.booleanReturns true if some option has been selected by the user, false otherwise.voidrenderImpl(FormData fd, Writer writer) This value (if set) is rendered as the html SIZE tag.voidsetValue(DependentSelect.Data data, List values) Convenience method to set values in the specifiedDependentSelect.Dataobject.voidSets the selected values for this select in the specified form data.voidsetValueFromSubmit(FormData fd, jakarta.servlet.http.HttpServletRequest req) This method sets the value of this field from the parameters obtained from the specified request.Methods inherited from class DependentField
addDependencyMethods inherited from class Field
add, addError, addLabel, addString, disable, disable, enable, enable, getLabel, getName, getValidateErrors, isEnabled, render, render, render, renderError, renderError, renderStyleTag, setStyleTag, toString, validate
-
Constructor Details
-
DependentSelect
Creates a new select element with no initial values. Multiple selections are not initially allowed.- Parameters:
name- the field name
-
-
Method Details
-
getType
Description copied from class:FieldSubclasses should return an appropriateField.Type. This type is rendered as part of <input type= ... -
getValue
Returns a List containing the selected options. Each object in the collection will be of typeSelect.Option. If there are no selected options, the returned list will be an empty list.- Parameters:
fd- the submited form data
-
getStringValue
Convenience method that returns the selected option as a String. No guarantees are made as to which selection is returned when more than one selection is selected (this method is really meant for when the select only allows single selections as a dropdown).The returned value is of type String obtained by called the selected Select.Option's
Select.Option.getValue()method.If there is no selection, returns null
-
getIntValue
Convenience method that returns the single value of this field as a Integer.All the caveats of
apply.invalid reference
#getSingleValueAsString()- Throws:
NumberFormatException- if the value could not be returned as in integer.
-
getBooleanValue
Convenience method that returns the single value of this field as a boolean.All the caveats of
apply. In particular, the formdata should contain non-null data with at least one selection.invalid reference
#getSingleValueAsString() -
isFilled
-
setValueFromSubmit
Description copied from class:FieldThis method sets the value of this field from the parameters obtained from the specified request. The name of the parameter to obtain this value will typically be the name of this field itself.- Specified by:
setValueFromSubmitin classField- Parameters:
fd- the form data object to store the value in- See Also:
-
renderImpl
- Specified by:
renderImplin classField- Throws:
SQLExceptionIOException
-
allowMultiple
true if multiple selections are allowed, false otherwise. This value (if set) is rendered as the html MULTIPLE tag.- Returns:
- this object for method chaining convenience
-
setSize
This value (if set) is rendered as the html SIZE tag. If the list contains more options than specified by size, the browser will display the selection list with scrollbars.- Returns:
- this object for method chaining convenience
-
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). The values are set in a newly createdDependentSelect.Dataobject which is then stored inside the form data. Since these are set in the FormData object, these values are request specific and can differ per 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:
values- a list ofSelect.Optionobjectsdata- an existing form data object.
-
setValue
Convenience method to set values in the specifiedDependentSelect.Dataobject. The following two are equivalent:
andList values ..... DependentSelect.Data data = new DependentSelect.Data(); fd.putData(name, data); setValue(data, values);
List values ..... setValue(fd, values);
- Parameters:
data- an existing DependentSelect.Data object.values- a list ofSelect.Optionobjects
-