|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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 like for a Select
.
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")); pickList.addSelectedValue("001");The selected values can be retrieved from
getSelectedValues()
.
Set selectedValues = pickList.getSelectedValues();
for (Iterator i = selectedValues.iterator(); i.hasNext();){
String value = (String) i.next();
...
}
Field Summary | |
---|---|
protected int |
height
The list height. |
static String |
HTML_IMPORTS
The Palette.js imports statement. |
protected List |
optionList
The Option list. |
protected String |
selectedLabel
The label text for the selected list. |
protected List |
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, readonly, required, tabindex, title, validate, value |
Fields inherited from class org.apache.click.control.AbstractControl |
---|
actionListener, attributes, 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(Option option)
Add the given Option to the PickList. |
void |
addAll(Collection options)
Add the given Option collection to the PickList. |
void |
addAll(Collection objects,
String value,
String label)
Add the given collection of objects to the PickList, 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 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. |
int |
getHeight()
Return the list height. |
String |
getHtmlImports()
Return the HTML head import statements for the JavaScript (click/extras-control.js) file. |
List |
getOptionList()
Return the Option list. |
List |
getSelectedValues()
Return the list of selected values as a List of Strings. |
int |
getSize()
Return the component size (width) in pixels. |
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 |
onDeploy(ServletContext servletContext)
Deploy the extras-control.js file to the click web directory when the application is initialized. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the PickList. |
protected void |
renderTemplate(HtmlStringBuffer buffer,
Map model)
Render a Velocity template for the given data model. |
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 |
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 selectedValues)
Set the list of selected values. |
void |
setSize(int size)
Set the component size. |
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, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, 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, setWidth |
Methods inherited from class org.apache.click.control.AbstractControl |
---|
addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getContext, getControlSizeEst, getHeadElements, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasStyles, onDestroy, onRender, removeStyleClass, renderTagBegin, 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 |
---|
public static final String HTML_IMPORTS
protected static final String VALIDATE_PICKLIST_FUNCTION
protected int height
protected List optionList
protected String selectedLabel
protected List 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 addAll(Collection options)
options
- the collection of Option objects to add
IllegalArgumentException
- if options is nullpublic 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)
PickList list = new PickList("type", "Type:"); list.addAll(getCustomerService().getCustomerTypes(), "id", "name); form.add(list);For example given the Collection of CustomerType objects, value "id" and label "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 value and label retrieved from the CustomerType
instance.
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 void setHeaderLabel(String unselectedLabel, String selectedLabel)
unselectedLabel
- the label text for the unselected listselectedLabel
- the label text for the selected listpublic List getOptionList()
public int getHeight()
public void setHeight(int height)
height
- the list heightpublic String getHtmlImports()
getHtmlImports
in interface Control
getHtmlImports
in class AbstractControl
Control.getHtmlImports()
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 getSelectedValues()
public void setSelectedValues(List 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 void onDeploy(ServletContext servletContext)
onDeploy
in interface Control
onDeploy
in class AbstractControl
servletContext
- the servlet contextControl.onDeploy(ServletContext)
public 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 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 |