packtpub.celebrities.util package:
package com.packtpub.celebrities.util;
import com.packtpub.celebrities.model.Celebrity;
import java.util.Map;
import org.apache.tapestry.OptionModel;
public class CelebrityOptionModel implements OptionModel
{
private Celebrity celebrity;
public CelebrityOptionModel(Celebrity celebrity)
{
this.celebrity = celebrity;
}
public String getLabel()
{
return celebrity.getFirstName() + " " +
celebrity.getLastName();
}
public boolean isDisabled()
{
return false;
}
public Map
getAttributes()
{
return null;
}
public Object getValue()
{
return celebrity;
}
}
The class is very simple, there is hardly anything worth commenting in it, so let's just
proceed to the next step.
Creating Custom Components
[ 208 ]
Creating a SelectModel
This is where we are going to create the model itself. The easiest way to do this is to
extend the AbstractSelectModel class that comes with Tapestry. In this case we
shall need to implement just two methods, and one of them will always return null.
List getOptions()??”returns a list of options to display,
using an implementation of OptionModel such as the one created above.
List getOptionGroups()??”used to display grouped
options.
Pages:
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262