public final class RefreshableSelect extends Select
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.
Select.Option
Field.Type
Constructor and Description |
---|
RefreshableSelect(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.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Select.Option opt)
Adds a new option to the selection list.
|
void |
add(String item)
Adds a new option to the selection list.
|
Select |
allowMultiple(boolean allow)
true is multiple selections are allowed, false otherwise.
|
boolean |
getBooleanValue(FormData fd)
Convenience method that returns the single value of this field
as a boolean.
|
int |
getIntValue(FormData fd)
Convenience method that returns the single value of this field
as a Integer.
|
String |
getStringValue(FormData fd)
Convenience method that returns the selected option as a
String.
|
Field.Type |
getType()
Subclasses should return an appropriate
Field.Type . |
List |
getValue(FormData fd)
Returns a List containing the selected options.
|
boolean |
isFilled(FormData fd)
Returns true if some option has been selected
by the user, false otherwise.
|
void |
renderImpl(FormData fd,
Writer writer) |
void |
reset()
Clears all data in this select.
|
void |
setSelectedValue(FormData fd,
int value)
Convenience method that invokes
#setSelectedValue(fd, String)
after converting the specified integer value to a string. |
void |
setSelectedValue(FormData fd,
String value)
Convenience method that sets the options for this select in the
specified form data.
|
Select |
setSize(int size)
This value (if set) is rendered as the html SIZE tag.
|
void |
setValue(FormData fd,
List values)
Sets the options for this select in the specified form data.
|
void |
setValueFromSubmit(FormData fd,
javax.servlet.http.HttpServletRequest req)
This method sets the value of this field from the parameters obtained from
the specified request.
|
makeOptionsFromQuery, makeOptionsFromQuery, setValue, useQuery, useQuery
add, addError, addLabel, addString, disable, disable, enable, enable, getLabel, getName, getValidateErrors, isEnabled, render, render, render, renderError, renderError, renderStyleTag, setStyleTag, toString, validate
public RefreshableSelect(String name)
name
- the field namepublic RefreshableSelect(String name, List values)
name
- the field namevalues
- the initial option values for this class. The
objects contained in the list must be of type
Select.Option
otherwise a
ClassCastException may be thrown in
future operations on this object.IllegalArgumentException
- if the values parameter was null
(note: an empty but non-null List is ok)public Field.Type getType()
Field
Field.Type
. This type
is rendered as part of <input type= ...public void setValue(FormData fd, List values)
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.
fd
- the non-null form data used for rendering the formvalues
- a list of Select.Option
objectspublic void setSelectedValue(FormData fd, String value)
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.
fd
- the non-null form data used for rendering the formvalue
- the option with this value is selectedpublic void setSelectedValue(FormData fd, int value)
#setSelectedValue(fd, String)
after converting the specified integer value to a string.public List getValue(FormData fd)
Select.Option
. If there
are no selected options, the returned list will be an
empty list.public String getStringValue(FormData fd)
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
getStringValue
in class Select
public int getIntValue(FormData fd)
All the caveats of #getSingleValueAsString()
apply.
getIntValue
in class Select
NumberFormatException
- if the value could not be
returned as in integer.public boolean getBooleanValue(FormData fd)
All the caveats of #getSingleValueAsString()
apply.
In particular, the formdata should contain non-null data
with at least one selection.
getBooleanValue
in class Select
public boolean isFilled(FormData fd)
public void setValueFromSubmit(FormData fd, javax.servlet.http.HttpServletRequest req) throws SubmitHackedException
Field
setValueFromSubmit
in class Select
fd
- the form data object to store the value inSubmitHackedException
public void renderImpl(FormData fd, Writer writer) throws IOException
renderImpl
in class Select
IOException
public void add(Select.Option opt)
public void add(String item)
add(new Select.Option(item))
method was invoked.public Select setSize(int size)
public Select allowMultiple(boolean allow)
allowMultiple
in class Select