Class RefreshableSelect
Select
in that is allows the values/options displayed by this select to be
changed dynamically/per-user via the setValue(FormData, List)
method.
There is no easy way to persistently keep track of these values which may be different for each user. Therefore, unlike other field classes, this class does (by default) no check to see if the returned values by the user match at least one of the values displayed to the user in the first place. This can happen if values are hacked on the client side.
Database constraints (that only accept valid values) should be used to possibly handle bad data returned by this field.
-
Nested Class Summary
Nested classes/interfaces inherited from class Select
Select.OptionNested classes/interfaces inherited from class Field
Field.Type -
Constructor Summary
ConstructorsConstructorDescriptionRefreshableSelect(String name) Creates a new select element with no initial values.RefreshableSelect(String name, List values) Creates a new select element with the specified initial values and no multiple selections allowed. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Select.Option opt) Adds a new option to the selection list.voidAdds a new option to the selection list.allowMultiple(boolean allow) true is 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) voidreset()Clears all data in this select.voidsetSelectedValue(FormData fd, int value) Convenience method that invokessetSelectedValue(fd, String)after converting the specified integer value to a string.voidsetSelectedValue(FormData fd, String value) Convenience method that sets the options for this select in the specified form data.setSize(int size) This value (if set) is rendered as the html SIZE tag.voidSets the options 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 Select
makeOptionsFromQuery, makeOptionsFromQuery, setValue, useQuery, useQueryMethods 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
-
RefreshableSelect
Creates a new select element with no initial values. Multiple selections are not initially allowed.- Parameters:
name- the field name
-
RefreshableSelect
Creates a new select element with the specified initial values and no multiple selections allowed. There is no explicit default selection which typically means the browser will show the first item in the list as the selection item.- Parameters:
name- the field namevalues- the initial option values for this class. The objects contained in the list must be of typeSelect.Optionotherwise a ClassCastException may be thrown in future operations on this object.- Throws:
IllegalArgumentException- if the values parameter was null (note: an empty but non-null List is ok)
-
-
Method Details
-
getType
Description copied from class:FieldSubclasses should return an appropriateField.Type. This type is rendered as part of <input type= ... -
setValue
Sets the options 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 formvalues- a list ofSelect.Optionobjects
-
setSelectedValue
Convenience method that sets the options for this select in the specified form data. All of the initial options are used and option corresponding to the specified value is selected. There must be some initial options set for this field and the specified value should match one of the initial options.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 selected value.
- Parameters:
fd- the non-null form data used for rendering the formvalue- the option with this value is selected
-
setSelectedValue
Convenience method that invokessetSelectedValue(fd, String)after converting the specified integer value to a string. -
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. -
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 Option's
Select.Option.getValue()method.If there is no selection, returns null
- Overrides:
getStringValuein classSelect
-
getIntValue
Convenience method that returns the single value of this field as a Integer.All the caveats of
apply.invalid reference
#getSingleValueAsString()- Overrides:
getIntValuein classSelect- 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()- Overrides:
getBooleanValuein classSelect
-
isFilled
-
setValueFromSubmit
public void setValueFromSubmit(FormData fd, jakarta.servlet.http.HttpServletRequest req) throws SubmitHackedException 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.- Overrides:
setValueFromSubmitin classSelect- Parameters:
fd- the form data object to store the value in- Throws:
SubmitHackedException
-
renderImpl
- Overrides:
renderImplin classSelect- Throws:
IOException
-
add
Adds a new option to the selection list. Replaces any previous option that was added previously with the same value. -
add
Adds a new option to the selection list. Replaces any previous option that was added previously with the same value. This method will have the same effect as if theadd(new Select.Option(item))method was invoked. -
reset
-
setSize
-
allowMultiple
true is multiple selections are allowed, false otherwise. This value (if set) is rendered as the html MULTIPLE tag.- Overrides:
allowMultiplein classSelect- Returns:
- this object for method chaining convenience
-