public class Select extends Field
There are 3 different kinds of selects:
Modifier and Type | Class and Description |
---|---|
static class |
Select.Option
Represents an option in the selection list
|
Field.Type
Constructor and Description |
---|
Select(String name)
Creates a new select element with no initial values.
|
Select(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.
|
static List |
makeOptionsFromQuery(Connection con,
String query)
Uses the first column as the option text and if there is a second column
uses it as the corresponding option value.
|
static List |
makeOptionsFromQuery(Connection con,
String query,
Select.Option defaultOption)
Uses the first column as the option text and if there is a second column
uses it as the corresponding option value.
|
void |
renderImpl(FormData fd,
Writer writer) |
void |
reset()
Clears all data in this select.
|
Select |
setSize(int size)
This value (if set) is rendered as the html SIZE tag.
|
void |
setValue(List values)
Sets the values for this select.
|
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.
|
Select |
useQuery(Connection con,
String query)
Convenience method that calls
useQuery(con, query, null) . |
Select |
useQuery(Connection con,
String query,
Select.Option defaultOpt)
The specified query is used to populate this select.
|
add, addError, addLabel, addString, disable, disable, enable, enable, getLabel, getName, getValidateErrors, isEnabled, render, render, render, renderError, renderError, renderStyleTag, setStyleTag, toString, validate
public Select(String name)
name
- the field namepublic Select(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 Select useQuery(Connection con, String query, Select.Option defaultOpt) throws SQLException
Typically, this method may be invoked like:
useQuery(con, "select id, name from my_lookup_table", new Option("--choose--"));If the lookup table has more than 2 columns, the query can look like (in standard SQL syntax):
useQuery(con, "select id, name1 || ' ' || name2 from my_lookup_table", new Option("--choose--"));This shows columns name1 and name2 concatenated with each other.
con
- the connection to use for the query. This connection is
not closed by this method. Close this connection
from the calling code to prevent connection leaks.SQLException
public Select useQuery(Connection con, String query) throws SQLException
useQuery(con, query, null)
.SQLException
public static List makeOptionsFromQuery(Connection con, String query) throws SQLException
SQLException
public static List makeOptionsFromQuery(Connection con, String query, Select.Option defaultOption) throws SQLException
SQLException
public Field.Type getType()
Field
Field.Type
. This type
is rendered as part of <input type= ...public void setValue(List values)
Note, to show user specific options via FormData, use a RefreshableSelect
instead.
values
- a list of Select.Option
objectspublic List getValue(FormData fd)
Select.Option
. If there
are no selected options, the returned list will be an
empty list.fd
- the submited form data. This object should not be null
otherwise a NPE will be thrown.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
public int getIntValue(FormData fd)
All the caveats of #getSingleValueAsString()
apply.
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.
public boolean isFilled(FormData fd)
public void setValueFromSubmit(FormData fd, javax.servlet.http.HttpServletRequest req) throws SubmitHackedException
Field
setValueFromSubmit
in class Field
fd
- the form data object to store the value inSubmitHackedException
public void renderImpl(FormData fd, Writer writer) throws IOException
renderImpl
in class Field
IOException
public void add(Select.Option opt)
opt
- the option to be addedpublic void add(String item)
add(new Select.Option(item))
method was invoked.item
- the option to be addedpublic void reset()
public Select setSize(int size)
public Select allowMultiple(boolean allow)