Wiki Markup |
---|
{scrollbar} |
Excerpt | ||
---|---|---|
| ||
Using SelectModel, SelectModelFactory and ValueEncoder for Select menus populated from a database |
...
In the above example, ColorSelectModel must be of type SelectModel, or anything that Tapestry knows how to coerce into a SelectModel, such as a List or a Map or a "value=label,value=label,..." delimited string, or anything Tapestry knows how to coerce into a List or Map, such as an Array or a comma-delimited String.
SelectModel
Wiki Markup |
---|
{float:right|background=#eee|padding=0 1em}
*JumpStart Demos:*
[Total Control Object Select| |
...
https://tapestry-jumpstart. |
...
org/jumpstart/examples/select/totalcontrolobject] [ID Select| |
...
https://tapestry-jumpstart. |
...
org/jumpstart/examples/select/id] [Easy ID Select| |
...
https://tapestry-jumpstart. |
...
org/jumpstart/examples/select/easyid] {float} |
A SelectModel is a collection of options (specifically OptionModel objects) for a drop-down menu. Basically, each option is a value (an object) and a label (presented to the user).
...
In addition to a SelectModel, your Select menu is likely to need a ValueEncoder. While a SelectModel is concerned only with how to construct a Select menu, a ValueEncoder is used when constructing the Select menu and when interpreting the encoded value that is submitted back to the server. A ValueEncoder is a converter between the type of objects you want to represent as options in the menu and the client-side encoded values that uniquely identify them, and vice-versa.
Wiki Markup |
---|
{float:right|background=#eee|padding=0 1em}
*JumpStart Demo:*
[Easy Object Select| |
...
https://tapestry-jumpstart. |
...
org/jumpstart/examples/select/easyobject] {float} |
Most commonly, your ValueEncoder's toClient() method will return a unique ID (e.g. a database primary key, or perhaps a UUID) of the given object, and its toValue() method will return the object matching the given ID by doing a database lookup (ideally using a service or DAO method).
...