|
|||||||||
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.CheckList
public class CheckList
Provides a check list control. This is an implementation of the Checklist from Check it don't select it
A check list is a more user friendly substitution for multiple-select-boxes. It is a scrollable div which has many select-boxes.public class MyPage extends Page { public void onInit() { CheckList checkList = new ChecList("languages"); checkList.add(new Option("001", "Java")); checkList.add(new Option("002", "Ruby")); checkList.add(new Option("003", "Perl")); // Set the Java as a selected option checkList.addSelectedValue("001"); } }Unless you use a DataProvider, remember to always populate the CheckList 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 CheckList to fetch data when needed. This is
particularly useful if retrieving CheckList 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 languageCheckList = new CheckList("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 languageCheckList.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(languageCheckList); form.add(new Submit("ok", " OK ")); } }CheckList also supports a scrollable mode. To make the CheckList scrollable, set the height of the CheckList through
setHeight(String)
.
Note when setting the height it is recommended that the CheckList
should not be sortable, because of browser incompatibilities.
The CheckList is also sortable by drag-drop if the
setSortable(boolean)
property is set to true. In this case the
method getSortorder()
returns the keys of all the options whether
they where selected or not in the order provided by the user.
Sortable is provided by scriptaculous which is only supported on IE6, FF and
Safari1.2 and higher. This control is only tested on IE6 and FF on Windows.
With IE the text of the dragged element has a black-outline which does not
look good. To turn this off define an explicit back-ground color for the
<li> elements. Typically you will do this in a style: .listClass li
{background-color: #xxx}, where the listClass is set through
AbstractControl.addStyleClass(String)
.
If a select is required at least one item must be
selected so that the input is valid. Other validations are not done.
The Control listener will be invoked in any case whether the CheckList is valid or not.
The values of the CheckList are provided by
Option
instances. To populate the CheckList with
Options, use the add methods.
The label of the Option is shown to the user and the value is what is
provided in the getSelectedValues()
and getSortorder()
Lists.
The selected values can be retrieved from getSelectedValues()
. The
get/setValue() property is not supported.
The select uses the /click/checklist/checklist.css style. By providing a style which
extends this style the appearance of the list can be changed.
To set the additional style class use AbstractControl.addStyleClass(String)
.
This will append the given class to the default class of this control.
Alternatively AbstractControl.setStyle(String, String)
can be used to set the style
of the outer div.
For an example please look at the click-examples and the at the above blog.
Option
,
Serialized FormField Summary | |
---|---|
protected DataProvider<Option> |
dataProvider
The select data provider. |
protected String |
height
The height if null not scrollable. |
protected List<Option> |
optionList
The Select Option list. |
protected List<String> |
selectedValues
The selected values. |
protected boolean |
sortable
If sortable by drag and drop. |
protected List<String> |
sortorder
The key of the values in the order they are present (only set when sortable). |
protected static String |
STYLE_CLASS
The style class which is always set on this element (checkList). |
protected static String |
VALIDATE_CHECKLIST_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 | |
---|---|
CheckList()
Create a CheckList field with no name defined. |
|
CheckList(String name)
Create a CheckList field with the given name. |
|
CheckList(String name,
boolean required)
Create a CheckList field with the given name and required status. |
|
CheckList(String name,
String label)
Create a CheckList field with the given name and label. |
|
CheckList(String name,
String label,
boolean required)
Create a CheckList field with the given name, label and required status. |
Method Summary | |
---|---|
void |
add(Object option)
Add the given Option/String/Number/Boolean to the CheckList. |
void |
add(Option option)
Add the given Option. |
void |
add(String value)
Add the given option value. |
void |
addAll(Collection<?> options)
Add the given Option/String/Number/Boolean collection to the CheckList. |
void |
addAll(Collection<?> objects,
String optionValueProperty,
String optionLabelProperty)
Add the given collection of objects to the CheckList, 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 CheckList. |
void |
addAll(String[] options)
Add the given array of string options to the Select option list. |
void |
addStyle(String style)
Deprecated. use @{link #setStyle(String, String)} |
void |
bindRequestValue()
Bind the request submission, setting the selectedValues and
sort order if the checkList is sortable. |
int |
getControlSizeEst()
|
DataProvider<Option> |
getDataProvider()
Return the CheckList optionList DataProvider. |
String |
getFocusJavaScript()
Return the Field focus JavaScript. |
List<Element> |
getHeadElements()
Return the CheckList HEAD elements to be included in the page. |
String |
getHeight()
The css-height attribute. |
String |
getHtmlClass()
Deprecated. use AbstractControl.getAttribute(String) instead |
List<Option> |
getOptionList()
Return the Option list. |
List<String> |
getSelectedValues()
Return the list of selected values as a List of Strings. |
List<String> |
getSortorder()
A list of the values transmitted in the order they are present in the list. |
String |
getTag()
|
String |
getValidationJavaScript()
Return the CheckList JavaScript client side validation function. |
Object |
getValueObject()
This method delegates to getSelectedValues() to return the
selected values as a java.util.List of Strings. |
List<String> |
getValues()
Deprecated. use getSelectedValues() instead |
boolean |
isSortable()
Whether the list is also sortable. |
boolean |
onProcess()
Process the request Context setting the CheckList selectedValues if selected and invoking the control's listener if defined. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the CheckList. |
void |
setDataProvider(DataProvider<Option> dataProvider)
Set the CheckList option list DataProvider. |
void |
setHeight(String height)
The css height attribute-value. |
void |
setHtmlClass(String clazz)
Deprecated. use AbstractControl.addStyleClass(String) instead |
void |
setOptionList(List<Option> options)
Set the Option list. |
void |
setSelectedValues(List<String> selectedValues)
Set the list of selected values. |
void |
setSortable(boolean sortable)
Whether the list should be drag-drop sortable. |
void |
setValueObject(Object object)
This method delegates to setSelectedValues(java.util.List)
to set the selected values of the CheckList. |
void |
setValues(List<String> values)
Deprecated. use setSelectedValues(List) instead |
protected void |
sortOptions(String[] order)
Sorts the current Options List. |
void |
validate()
Validate the CheckList request submission. |
Methods inherited from class org.apache.click.control.Field |
---|
getError, getErrorLabel, getFocus, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getState, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, 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, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, 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 STYLE_CLASS
protected static final String VALIDATE_CHECKLIST_FUNCTION
protected DataProvider<Option> dataProvider
protected String height
protected List<Option> optionList
protected boolean sortable
protected List<String> sortorder
protected List<String> selectedValues
Constructor Detail |
---|
public CheckList(String name)
name
- the name of the fieldpublic CheckList(String name, String label)
name
- the name of the fieldlabel
- the label of the fieldpublic CheckList(String name, boolean required)
name
- the name of the fieldrequired
- the field required statuspublic CheckList(String name, String label, boolean required)
name
- the name of the fieldlabel
- the label of the fieldrequired
- the field required statuspublic CheckList()
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(String value)
Option
with the given value and add it to the CheckList. 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 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)
CheckList list = new CheckList("type", "Type:"); list.addAll(getCustomerService().getCustomerTypes(), "id", "name"); form.add(select);For example given the 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<Option> dataProvider)
CheckList checkList = new CheckList("languages"); 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 CheckList option list DataProviderpublic void addStyle(String style)
list.addStyle(""width: 100%; height: 25em"");
style
- the style name:value pair without a ending ;public String getFocusJavaScript()
getFocusJavaScript
in class Field
public void setHeight(String height)
height
- one of css height values (ie 40px) or null.public String getHeight()
public void setHtmlClass(String clazz)
AbstractControl.addStyleClass(String)
instead
STYLE_CLASS
. Ie class="checkList my-class"
where my-class is the set class. The default value is null.
clazz
- the class to set or nullpublic String getHtmlClass()
AbstractControl.getAttribute(String)
instead
setHtmlClass(String)
public List<Element> getHeadElements()
getHeadElements
in interface Control
getHeadElements
in class AbstractControl
Control.getHeadElements()
public List<Option> getOptionList()
public void setOptionList(List<Option> options)
options
- a list of Option objectspublic void setSortable(boolean sortable)
sortable
- default is false.public boolean isSortable()
public List<String> getSortorder()
public List<String> getValues()
getSelectedValues()
instead
public List<String> getSelectedValues()
public void setValues(List<String> values)
setSelectedValues(List)
instead
values
- a list of strings or nullpublic void setSelectedValues(List<String> selectedValues)
CheckList checkList = new CheckList("checkList"); public void onInit() { List options = new ArrayList(); options.add(new Option("1", "Option 1"); options.add(new Option("2", "Option 2"); options.add(new Option("3", "Option 3"); checkList.setOptionList(options); ... } public void onRender() { // Preselect some Options. List selected = new ArrayList(); selected.add("1")); selected.add("3"); checkList.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 CheckList. 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 String getValidationJavaScript()
getValidationJavaScript
in class Field
public void bindRequestValue()
selectedValues
and
sort order if the checkList is sortable.
bindRequestValue
in class Field
public boolean onProcess()
onProcess
in interface Control
onProcess
in class Field
protected void sortOptions(String[] order)
bindRequestValue()
when the CheckList
is sortable.
order
- values in the order to sort the list.public int getControlSizeEst()
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,
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:
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |