|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.control.AbstractControl org.apache.click.control.Field org.apache.click.extras.control.PickList
public class PickList
Provides a twin multiple Select box control to select items.
|
PickList
are provided by Option
objects similar to a Select
field.
public class MyPage extends Page { public void onInit() { PickList pickList = new PickList("languages"); pickList.setHeaderLabel("Languages", "Selected"); pickList.add(new Option("001", "Java")); pickList.add(new Option("002", "Ruby")); pickList.add(new Option("003", "Perl")); // Set the Java as a selected option pickList.addSelectedValue("001"); } }Unless you use a DataProvider, remember to always populate the PickList option list before it is processed. Do not populate the option list in a Page's onRender() method.
optionList
in. To alleviate
this problem you can set a
dataProvider
which allows the PickList to fetch data when needed. This is
particularly useful if retrieving PickList data is expensive e.g. loading
from a database.
Below is a simple example:
public class LanguagePage extends Page { public Form form = new Form(); private Select languagePickList = new PickList("languages"); public LanguagePage() { // Set a DataProvider which "getData" method will be called to // populate the optionList. The "getData" method is only called when // the optionList data is needed languagePickList.setDataProvider(new DataProvider() { public List getData() { List options = new ArrayList(); options.add(new Option("001", "Java")); options.add(new Option("002", "Ruby")); options.add(new Option("003", "Perl")); return options; } }); form.add(languagePickList); form.add(new Submit("ok", " OK ")); } }
getSelectedValues()
.
public void onInit() { ... form.add(pickList); // Add a submit button with a listener form.add(new Submit("OK", this, "onSubmitClick")); } public boolean onSubmitClick() { if (form.isValid()) { Set selectedValues = languagePickList.getSelectedValues(); for (Object languageValue : selectedValues) { ... } } }
Field Summary | |
---|---|
protected DataProvider<Option> |
dataProvider
The select data provider. |
protected int |
height
The list height. |
protected List<Option> |
optionList
The Option list. |
protected String |
selectedLabel
The label text for the selected list. |
protected List<String> |
selectedValues
The selected values. |
protected int |
size
The component size (width) in pixels. |
protected String |
unselectedLabel
The label text for the unselected list. |
protected static String |
VALIDATE_PICKLIST_FUNCTION
The field validation JavaScript function template. |
Fields inherited from class org.apache.click.control.Field |
---|
disabled, error, focus, form, help, label, labelStyle, labelStyleClass, parentStyleClassHint, parentStyleHint, readonly, required, tabindex, title, trim, validate, value |
Fields inherited from class org.apache.click.control.AbstractControl |
---|
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface org.apache.click.Control |
---|
CONTROL_MESSAGES |
Constructor Summary | |
---|---|
PickList()
Create a PickList with no name defined. |
|
PickList(String name)
Create a PickList field with the given name. |
|
PickList(String name,
String label)
Create a PickList field with the given name and label. |
Method Summary | |
---|---|
void |
add(Object option)
Add the given Option/String/Number/Boolean to the PickList. |
void |
add(Option option)
Add the given Option to the PickList. |
void |
addAll(Collection<?> options)
Add the given Option/String/Number/Boolean collection to the PickList. |
void |
addAll(Collection<?> objects,
String optionValueProperty,
String optionLabelProperty)
Add the given collection of objects to the PickList, creating new Option instances based on the object properties specified by optionValueProperty and optionLabelProperty. |
void |
addAll(Map<?,?> options)
Add the given Map of option values and labels to the PickList. |
void |
addAll(String[] options)
Add the given array of string options to the PickList. |
void |
addSelectedValue(String value)
Add the selected value to the List of selectedValues . |
void |
bindRequestValue()
Bind the request submission, setting the selectedValues
property if defined in the request. |
DataProvider<Option> |
getDataProvider()
Return the PickList optionList DataProvider. |
List<Element> |
getHeadElements()
Returns the PickList HTML HEAD elements for the click/extras-control.js resource. |
int |
getHeight()
Return the list height. |
List<Option> |
getOptionList()
Return the Option list. |
List<String> |
getSelectedValues()
Return the list of selected values as a List of Strings. |
int |
getSize()
Return the component size (width) in pixels. |
Object |
getState()
Return the PickList state. |
String |
getValidationJavaScript()
Return the field JavaScript client side validation function. |
Object |
getValueObject()
This method delegates to getSelectedValues() to return the
selected values as a java.util.List of Strings. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the PickList. |
protected void |
renderTemplate(HtmlStringBuffer buffer,
Map<String,Object> model)
Render a Velocity template for the given data model. |
void |
setDataProvider(DataProvider dataProvider)
Set the PickList option list DataProvider. |
void |
setHeaderLabel(String unselectedLabel,
String selectedLabel)
Set the header label text for the selected list and the unselected list. |
void |
setHeight(int height)
Set the list height. |
void |
setOptionList(List<Option> options)
Set the Option list. |
void |
setSelectedValues(Collection<?> objects,
String value)
The PickList selected values will be derived from the given collection of objects, based on the object properties specified by value. |
void |
setSelectedValues(List<String> selectedValues)
Set the list of selected values. |
void |
setSize(int size)
Set the component size. |
void |
setState(Object state)
Set the PickList state. |
void |
setValueObject(Object object)
This method delegates to setSelectedValues(java.util.List)
to set the selected values of the PickList. |
String |
toString()
Return a HTML rendered PickList string. |
void |
validate()
Validate the PickList request submission. |
Methods inherited from class org.apache.click.control.Field |
---|
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, onProcess, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setValue, setWidth |
Methods inherited from class org.apache.click.control.AbstractControl |
---|
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final String VALIDATE_PICKLIST_FUNCTION
protected DataProvider<Option> dataProvider
protected int height
protected List<Option> optionList
protected String selectedLabel
protected List<String> selectedValues
protected int size
protected String unselectedLabel
Constructor Detail |
---|
public PickList(String name, String label)
name
- the name of the fieldlabel
- the label of the fieldpublic PickList(String name)
name
- the name of the fieldpublic PickList()
Method Detail |
---|
public void add(Option option)
option
- the Option value to add
IllegalArgumentException
- if option is nullpublic void add(Object option)
option
- one of either Option/String/Number/Boolean to add
IllegalArgumentException
- if option is null, or the option
is an unsupported classpublic void addAll(Collection<?> options)
options
- the collection of Option/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 optionValueProperty, String optionLabelProperty)
PickList list = new PickList("type", "Type:"); list.addAll(getCustomerService().getCustomerTypes(), "id", "name); form.add(list);For example, given a Collection of CustomerType objects, optionValueProperty "id" and optionLabelProperty "name", the id and name properties of each CustomerType will be retrieved. For each CustomerType in the Collection a new
Option
instance is created and its
value and label is set to the id
and name retrieved from the CustomerType instance.
objects
- the collection of objects to render as optionsoptionValueProperty
- the name of the object property to render as
the Option valueoptionLabelProperty
- the name of the object property to render as
the Option label
IllegalArgumentException
- if objects or optionValueProperty
parameter is nullpublic DataProvider<Option> getDataProvider()
public void setDataProvider(DataProvider dataProvider)
PickList pickList = new PickList("languages"); pickList.setHeaderLabel("Languages", "Selected"); select.setDataProvider(new DataProvider() { public List getData() { List options = new ArrayList(); options.add(new Option("001", "Java")); options.add(new Option("002", "Ruby")); options.add(new Option("003", "Perl")); return options; } });
dataProvider
- the PickList option list DataProviderpublic void setHeaderLabel(String unselectedLabel, String selectedLabel)
unselectedLabel
- the label text for the unselected listselectedLabel
- the label text for the selected listpublic List<Option> getOptionList()
public void setOptionList(List<Option> options)
options
- the Option listpublic int getHeight()
public void setHeight(int height)
height
- the list heightpublic List<Element> getHeadElements()
getHeadElements
in interface Control
getHeadElements
in class AbstractControl
Control.getHeadElements()
public void setSelectedValues(Collection<?> objects, String value)
PickList list = new PickList("type", "Type:"); // Fill the PickList with product types list.addAll(getCustomerService().getProductTypes(), "id", "name"); // Set the PickList selected values to the list of products of the // current customer list.setSelectedValues(getCustomer().getProductTypes(), "id"); form.add(list);For example given the Collection of ProductType objects and the value "id", the id property of each ProductType will be retrieved and added to the PickList
selectedValues
.
objects
- the collection of objects to render selected valuesvalue
- the name of the object property to render as the Option value
IllegalArgumentException
- if options or value parameter is nullpublic void addSelectedValue(String value)
selectedValues
.
value
- the selected value to add
IllegalArgumentException
- if the value is nullpublic List<String> getSelectedValues()
public void setSelectedValues(List<String> selectedValues)
PickList pickList = new PickList("languages"); public void onInit() { pickList.add(new Option("005", "Java")); pickList.add(new Option("006", "Ruby")); pickList.add(new Option("007", "Perl")); ... } public void onRender() { // Preselect Java and Perl. List selected = new ArrayList(); selected.add("005"); selected.add("007"); pickList.setSelectedValues(selected); }
selectedValues
- the list of selected string values or nullpublic Object getValueObject()
getSelectedValues()
to return the
selected values as a java.util.List of Strings.
getValueObject
in class Field
Field.getValueObject()
,
getSelectedValues()
public void setValueObject(Object object)
setSelectedValues(java.util.List)
to set the selected values of the PickList. The given object
parameter must be a java.util.List of Strings, otherwise it is
ignored.
The List of values match the values of the Options.
setValueObject
in class Field
object
- a List of StringsField.setValueObject(java.lang.Object)
,
setSelectedValues(java.util.List)
public void setSize(int size)
size
- the component sizepublic int getSize()
public String getValidationJavaScript()
getValidationJavaScript
in class Field
public void bindRequestValue()
selectedValues
property if defined in the request.
bindRequestValue
in class Field
public Object getState()
getState
in interface Stateful
getState
in class Field
public void setState(Object state)
setState
in interface Stateful
setState
in class Field
state
- the PickList state to setpublic void validate()
Error message bundle key names include:org.apache.click.control.MessageProperties
- field-required-error
validate
in class Field
public void render(HtmlStringBuffer buffer)
render
in interface Control
render
in class AbstractControl
buffer
- the specified buffer to render the control's output totoString()
public String toString()
toString
in class AbstractControl
protected void renderTemplate(HtmlStringBuffer buffer, Map<String,Object> model)
buffer
- the specified buffer to render the template output tomodel
- the model data to merge with the template
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |