public final class DependentSelect extends DependentField
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.
Modifier and Type | Class and Description |
---|---|
static class |
DependentSelect.Data |
Field.Type
Constructor and Description |
---|
DependentSelect(String name)
Creates a new select element with no initial values.
|
Modifier and Type | Method and Description |
---|---|
DependentSelect |
allowMultiple(FormData fd,
boolean allow)
true if 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) |
DependentSelect |
setSize(FormData fd,
int size)
This value (if set) is rendered as the html SIZE tag.
|
void |
setValue(DependentSelect.Data data,
List values)
Convenience method to set values in the specified
DependentSelect.Data object. |
void |
setValue(FormData fd,
List values)
Sets the selected values 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.
|
addDependency
add, addError, addLabel, addString, disable, disable, enable, enable, getLabel, getName, getValidateErrors, isEnabled, render, render, render, renderError, renderError, renderStyleTag, setStyleTag, toString, validate
public DependentSelect(String name)
name
- the field namepublic Field.Type getType()
Field
Field.Type
. This type
is rendered as part of <input type= ...public List getValue(FormData fd)
Select.Option
. If there
are no selected options, the returned list will be an empty list.fd
- the submited form datapublic String getStringValue(FormData fd)
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
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)
Field
setValueFromSubmit
in class Field
fd
- the form data object to store the value inSelect.setValueFromSubmit(fc.web.forms.FormData, javax.servlet.http.HttpServletRequest)
public void renderImpl(FormData fd, Writer writer) throws SQLException, IOException
renderImpl
in class Field
SQLException
IOException
public DependentSelect allowMultiple(FormData fd, boolean allow)
public DependentSelect setSize(FormData fd, int size)
public void setValue(FormData fd, List values)
DependentSelect.Data
object 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.
data
- an existing form data object.values
- a list of Select.Option
objectspublic void setValue(DependentSelect.Data data, List values)
DependentSelect.Data
object.
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);
data
- an existing DependentSelect.Data object.values
- a list of Select.Option
objects