After all that we have done with the
Celebrity class, the code will be trivial, so let's just look at it, and I bet you will be
able to figure out how it works without any help.
First of all, here is an implementation of OptionModel:
package com.packtpub.celebrities.util;
import java.util.Map;
import org.apache.tapestry.OptionModel;
public class IntegerOptionModel implements OptionModel
{
private Number number;
public IntegerOptionModel(Number num)
{
number = num;
}
public Map
getAttributes()
{
return null;
}
public String getLabel()
{
return "" + number;
}
public Object getValue()
{
return number;
}
public boolean isDisabled()
Chapter 8
[ 213 ]
{
return false;
}
}
Next, we need to have a SelectModel, and this is how it could look:
package com.packtpub.celebrities.util;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry.OptionGroupModel;
import org.apache.tapestry.OptionModel;
import org.apache.tapestry.util.AbstractSelectModel;
public class IntegerSelectModel extends AbstractSelectModel
{
private List options =
new ArrayList();
public IntegerSelectModel(int numFrom, int numTo)
{
int increment = numTo > numFrom ? 1 : -1;
for (int i = numFrom; i <= numTo; i += increment)
{
options.
Pages:
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268