|
||||||||||
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.extras.control.CheckList
Provides a scrollable check list. This is an implementation of the Checklist from Check it don't select it
A scrollable check list is a more user friendly substitution for multiple-select-boxes. It is a scrollabe div which has many select-boxes. To make the CheckList scrollable, set the height of the CheckList throughsetHeight(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.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 String |
height
The height if null not scrollable. |
static String |
HTML_IMPORTS
The HTML import statements. |
static String |
JS_SORT_HTML_IMPORTS
The JavaScript sorting HTML import statements. |
protected List |
optionList
The Select Option list. |
protected List |
selectedValues
The selected values. |
protected boolean |
sortable
If sortable by drag and drop. |
protected List |
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 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 | |
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(Option option)
Add the given Option. |
void |
add(String value)
Add the given option value. |
void |
addAll(Collection options)
Add the given Option collection to the CheckList. |
void |
addAll(Collection objects,
String value,
String label)
Add the given collection of objects to the CheckList, 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 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()
|
String |
getFocusJavaScript()
Return the Field focus JavaScript. |
String |
getHeight()
The css-height attribute. |
String |
getHtmlClass()
Deprecated. use AbstractControl.getAttribute(String) instead |
String |
getHtmlImports()
Returns the CSS and JavaScript imports and adds the script the checklist onload event. |
List |
getOptionList()
Return the Option list. |
List |
getSelectedValues()
Return the list of selected values. |
List |
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()
Returns the values list getValues() return a list or String. |
List |
getValues()
Deprecated. use getSelectedValues() instead |
boolean |
isSortable()
Whether the list is also sortable. |
void |
onDeploy(ServletContext servletContext)
Deploys the style-sheet 'checklist.css' to the /click directory. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the CheckList. |
void |
setHeight(String height)
The css height attribute-value. |
void |
setHtmlClass(String clazz)
Deprecated. use AbstractControl.addStyleClass(String) instead |
void |
setOptionList(List options)
Set the Option list. |
void |
setSelectedValues(List selectedValues)
Set the list of selected values. |
void |
setSortable(boolean sortable)
Whether the list should be drag-drop sortable. |
void |
setValueObject(Object object)
Set the value the value must be a List of String. |
void |
setValues(List 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 net.sf.click.control.Field |
getError, getErrorLabel, getFocus, 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 net.sf.click.control.AbstractControl |
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, 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 |
public static final String HTML_IMPORTS
public static final String JS_SORT_HTML_IMPORTS
protected static final String STYLE_CLASS
protected static final String VALIDATE_CHECKLIST_FUNCTION
protected String height
protected List optionList
protected boolean sortable
protected List sortorder
protected List 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()
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 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)
CheckList list = new CheckList("type", "Type:"); list.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 void addStyle(String style)
list.addStyle(""width: 100%; height: 25em"");
style
- the style name:value pair without a ending ;public String getFocusJavaScript()
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 String getHtmlImports()
AbstractControl.getHtmlImports()
public List getOptionList()
public void setOptionList(List options)
options
- a list of Option objectspublic void setSortable(boolean sortable)
sortable
- default is false.public boolean isSortable()
public List getSortorder()
public List getValues()
getSelectedValues()
instead
public List getSelectedValues()
public void setValues(List values)
setSelectedValues(List)
instead
values
- a list of strings or nullpublic void setSelectedValues(List 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()
getValues()
return a list or String.
Field.getValueObject()
public void setValueObject(Object object)
object
- a List or nullField.setValueObject(java.lang.Object)
public String getValidationJavaScript()
public void bindRequestValue()
selectedValues
and
sort order if the checkList is sortable.
protected void sortOptions(String[] order)
bindRequestValue()
when the CheckList
is sortable.
order
- values in the order to sort the list.public void onDeploy(ServletContext servletContext)
servletContext
- the contextAbstractControl.onDeploy(javax.servlet.ServletContext)
public int getControlSizeEst()
AbstractControl.getControlSizeEst()
public void render(HtmlStringBuffer buffer)
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:
Overview Package Class Tree Deprecated Index Help PREV CLASS NEXT CLASS FRAMES NO FRAMES SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD