Here is how they
can be provided by the page class:
public SelectModel getCelebrityModel()
{
return new CelebritySelectModel(getAllCelebrities());
}
public ValueEncoder getCelebrityEncoder()
{
return new CelebrityEncoder(dataSource);
}
Chapter 8
[ 211 ]
@Persist
private Celebrity selectedCelebrity;
public Celebrity getSelectedCelebrity()
{
return selectedCelebrity;
}
public void setSelectedCelebrity(Celebrity selectedCelebrity)
{
this.selectedCelebrity = selectedCelebrity;
}
All the methods are one-liners! Even the method that provides the celebrity's name
for the expansion looks more complex:
public String getSelectedCelebrityName()
{
if (selectedCelebrity == null) return "";
return selectedCelebrity.getFirstName() + " " +
selectedCelebrity.getLastName();
}
If you run the application now, you should see a drop-down box with celebrities'
names in it. If you select a celebrity and submit your selection, his or her name
should appear properly underneath.
Now we know how to teach the Select component to do whatever we want it to
do, and we are going to use this knowledge in the next sections to build some useful
custom components.
DateInput Component
In Chapter 5 we became familiar with the DateField component.
Pages:
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266