-
Book Overview & Buying
-
Table Of Contents
Tapestry 5: Building Web Applications
The first step in creating a custom model is to define how Tapestry should handle a single object of those to be displayed by the Select component. Here we shall be thinking in terms of a single<option> element and, fair enough, the name of the interface which we need to implement is OptionModel. This interface has four methods, but only two of them will be important for us:
String getLabel() returns a label for the given option.
Object getValue()—despite its name, this method should return not the contents for the value attribute but rather the object that corresponds to the option.
The other two methods, isDisabled() and getAttributes(), can be used to define whether the option should be disabled and what other attributes it should have. In many cases, they will return false and null respectively.
Here is the code for CelebrityOptionModel, an implementation of OptionModel that knows how to deal with the Celebrity object. Let's add this class to the com.packtpub...
Change the font size
Change margin width
Change background colour