|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.control.AbstractControl net.sf.click.control.Field net.sf.click.control.Select
Provides a Select control: <select></select>.
Select |
multiple
item property is false.
If a Select is required, an item after the first in the list must be selected
for the Field to be valid. This forces the user to make an active selection.
An example of a single item Select is provided below along with the
rendered HTML.
public class GenderPage extends Page { public Form form = new Form(); private Select genderSelect = new Select("Gender"); public GenderPage() { genderSelect.setRequired(true); genderSelect.add(new Option("U", ""); genderSelect.add(new Option("M", "Male")); genderSelect.add(new Option("F", "Female")); form.add(genderSelect); form.add(new Submit("ok", " OK ")); } public void onPost() { if (form.isValid()) { String gender = genderSelect.getValue(); .. } } }Rendered HTML:
|
Option
items are added to the Select. In this
example the "U" option will not be a valid selection, as it is the first
item in the option list.
multiple
item property is false, and must be
enabled for multiple item selects.
If multiple item Select is required, the user must select an item(s) in
the list for the Field to be valid. A valid selection can include any item
including the first item.
An example of a single item Select is provided below along with the
rendered HTML.
public class LocationPage extends Page { public Form form = new Form(); private Select locationSelect = new Select("location"); public LocationPage() { locationSelect.setMutliple(true); locationSelect.setRequired(true); locationSelect.setSize(7); locationSelect.add("QLD"); locationSelect.add("NSW"); locationSelect.add("NT"); locationSelect.add("SA"); locationSelect.add("TAS"); locationSelect.add("VIC"); locationSelect.add("WA"); form.add(locationSelect); form.add(new Submit("ok", " OK ")); } public void onPost() { if (form.isValid()) { String location = locationSelect.getValue(); .. } } }Rendered HTML:
|
add(String)
method is used to add an Option
item to the Select.
Page.onRender()
method:
public MyPage extends Page { private Select mySelect; public MyPage() { mySelect = new Select("mySelect"); mySelect.add("YES"); mySelect.add("NO"); } public void onRender() { // Only specify a default value if the current value is null if (mySelect.getValue() == null) { mySelect.setValue("YES"); } } }
Option
,
OptionGroup
,
Serialized FormField Summary | |
protected boolean |
multiple
The multiple options selectable flag. |
protected List |
optionList
The Select Option/OptionGroup list. |
protected List |
selectedValues
The multiple selected values. |
protected int |
size
The Select display size in rows. |
protected static String |
VALIDATE_SELECT_FUNCTION
The field validation JavaScript function template. |
Fields inherited from class net.sf.click.control.Field |
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value |
Fields inherited from class net.sf.click.control.AbstractControl |
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface net.sf.click.Control |
CONTROL_MESSAGES |
Constructor Summary | |
Select()
Create a Select field with no name defined. |
|
Select(String name)
Create a Select field with the given name. |
|
Select(String name,
boolean required)
Create a Select field with the given name and required status. |
|
Select(String name,
String label)
Create a Select field with the given name and label. |
|
Select(String name,
String label,
boolean required)
Create a Select field with the given name, label and required status. |
Method Summary | |
void |
add(Option option)
Add the given Option to the Select. |
void |
add(OptionGroup optionGroup)
Add the given OptionGroup to the Select. |
void |
add(String value)
Add the given option value to the Select. |
void |
addAll(Collection options)
Add the given Option/OptionGroup/String/Number/Boolean collection to the Select. |
void |
addAll(Collection objects,
String value,
String label)
Add the given collection of objects to the Select, creating new Option instances based on the object properties specified by value and label. |
void |
addAll(Map options)
Add the given Map of option values and labels to the Select. |
void |
addAll(String[] options)
Add the given array of string options to the Select option list. |
void |
bindRequestValue()
Bind the request submission, setting the Field.value or
selectedValues property if defined in the request. |
int |
getControlSizeEst()
Return the estimated rendered control size in characters. |
List |
getMultipleValues()
Deprecated. use getSelectedValues() instead, this method will
be removed in subsequent releases |
List |
getOptionList()
Return the Option list. |
List |
getSelectedValues()
Return the list of selected values. |
int |
getSize()
Return the number of Select display rows. |
String |
getTag()
Return the select's html tag: select. |
String |
getValidationJavaScript()
Return the Select JavaScript client side validation function. |
boolean |
isMultiple()
Return true if multiple options can be selected. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the Select. |
protected void |
setInitialValue()
Set the initial select option value. |
void |
setMultiple(boolean value)
Set the multiple options can be selected flag. |
void |
setMultipleValues(List multipleValues)
Deprecated. use getSelectedValues() instead, this method will
be removed in subsequent releases |
void |
setOptionList(List options)
Set the Option list. |
void |
setSelectedValues(List multipleValues)
Set the list of selected values. |
void |
setSize(int rows)
Set the number of the Select display rows. |
void |
validate()
Validate the Select request submission. |
Methods inherited from class net.sf.click.control.Field |
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setValueObject, setWidth |
Methods inherited from class net.sf.click.control.AbstractControl |
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final String VALIDATE_SELECT_FUNCTION
protected boolean multiple
protected List optionList
protected int size
protected List selectedValues
multiple
is true.
Constructor Detail |
public Select(String name)
name
- the name of the fieldpublic Select(String name, String label)
name
- the name of the fieldlabel
- the label of the fieldpublic Select(String name, boolean required)
name
- the name of the fieldrequired
- the field required statuspublic Select(String name, String label, boolean required)
name
- the name of the fieldlabel
- the label of the fieldrequired
- the field required statuspublic Select()
Method Detail |
public String getTag()
getTag
in class AbstractControl
AbstractControl.getTag()
public void add(Option option)
option
- the Option value to add
IllegalArgumentException
- if option is nullpublic void add(OptionGroup optionGroup)
optionGroup
- the OptionGroup value to add
IllegalArgumentException
- if optionGroup is nullpublic void add(String value)
Option
with the given value and add it to the
Select. The new Option display label will be the same as its value.
value
- the option value to add
IllegalArgumentException
- if the value is nullpublic void addAll(Collection options)
options
- the collection of Option/OptionGroup/String/Number/Boolean
objects to add
IllegalArgumentException
- if options is null, or the collection
contains an unsupported classpublic void addAll(Map options)
options
- the Map of option values and labels to add
IllegalArgumentException
- if options is nullpublic void addAll(String[] options)
Option.value
and Option.label
.
options
- the array of option values to add
IllegalArgumentException
- if options is nullpublic void addAll(Collection objects, String value, String label)
Select select = new Select("type", "Type:"); select.addAll(getCustomerService().getCustomerTypes(), "id", "name"); form.add(select);
objects
- the collection of objects to render as optionsvalue
- the name of the object property to render as the Option valuelabel
- the name of the object property to render as the Option label
IllegalArgumentException
- if options, value or label parameter is nullpublic int getSize()
public void setSize(int rows)
rows
- the Select display size in rows.public boolean isMultiple()
public void setMultiple(boolean value)
value
- the multiple options can be selected flagpublic List getMultipleValues()
getSelectedValues()
instead, this method will
be removed in subsequent releases
public List getSelectedValues()
public void setMultipleValues(List multipleValues)
getSelectedValues()
instead, this method will
be removed in subsequent releases
multipleValues
- the list of selected valuespublic void setSelectedValues(List multipleValues)
multipleValues
- the list of selected valuespublic List getOptionList()
public void setOptionList(List options)
options
- the Option listpublic String getValidationJavaScript()
getValidationJavaScript
in class Field
public void bindRequestValue()
Field.value
or
selectedValues
property if defined in the request.
bindRequestValue
in class Field
public int getControlSizeEst()
AbstractControl
getControlSizeEst
in class AbstractControl
AbstractControl.getControlSizeEst()
public void render(HtmlStringBuffer buffer)
render
in interface Control
render
in class AbstractControl
buffer
- the specified buffer to render the control's output toAbstractControl.toString()
public void validate()
Field.required
then the user must select a value
other than the first value is the list, otherwise the Select will
have a validation error. If the Select is not required then no
validation errors will occur.
A field error message is displayed if a validation error occurs.
These messages are defined in the resource bundle: Error message bundle key names include:/click-control.properties
- select-error
validate
in class Field
protected void setInitialValue()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |