Interface ListModel
-
- All Known Implementing Classes:
TextListModelTag.TextListModel
public interface ListModel
Definition of an interface that is used to obtain the content of a list box or combo box component.
When lists or combo boxes or similar components are to be displayed their content must be specified. This can be a list of static texts in the most simple cases, but also the results of a data base query. To support all of these possibilities the form builder library introduces this interface which serves as an abstraction of a real data source.
This interface defines methods for obtaining the data to be displayed. The displayed data need not be the same that will be stored in the form bean for this element, so it is also possible to define a specific value for each element to be displayed. The
getType()
method will determine the data type of the corresponding property in the form bean.- Version:
- $Id: ListModel.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Object
getDisplayObject(int index)
Returns the display object with the given index.Class<?>
getType()
Returns the data object of this list model.Object
getValueObject(int index)
Returns the value object with the given index.int
size()
Returns the number of entries in this model.
-
-
-
Method Detail
-
size
int size()
Returns the number of entries in this model.- Returns:
- the number of entries
-
getDisplayObject
Object getDisplayObject(int index)
Returns the display object with the given index. This object will be displayed in the list box (or its string representation respective). A concrete implementation must never return null .- Parameters:
index
- the index (0 based)- Returns:
- the display object at this index
-
getValueObject
Object getValueObject(int index)
Returns the value object with the given index.
This method makes sense when the display objects are different from the values that should be stored when corresponding display objects are selected. E.g. the display objects might be simple strings that represent complex data objects. When a string is selected the component's data really is the data object behind this string. In this case the
getValueObject()
method would return the complex data objects, whilegetDisplayObject()
would return corresponding string representations.When working with a fix set of options from which the user can select one or some, it is often useful to store the indices of the selected display objects. Imagine a combo box that offer the choices "yes", "no", and "maybe". In the bean of the form that contains this combo box it makes sense to store the values 0, 1, or 2 depending on the user's selection rather than the (language dependend) string values. To achieve this, the
getValueObject()
method can always return null . Then as values always the corresponding indices will be used as values. Note: an implementation must not mix these variants; either it must return null for all of its values or none.- Parameters:
index
- the index (0 based)- Returns:
- the value object for this index
-
getType
Class<?> getType()
Returns the data object of this list model. This is the type of the value objects stored in the data property for the corresponding component.- Returns:
- the data type of this model
-
-