add(new IntegerOptionModel(i));
}
}
public List
getOptionGroups()
{
return null;
}
public List getOptions()
{
return options;
}
}
We are also going to need a ValueEncoder, as the current version of Tapestry 5
doesn't know how to deal with integers yet. But it will be very simple:
package com.packtpub.celebrities.util;
import org.apache.tapestry.ValueEncoder;
public class IntegerEncoder implements ValueEncoder
{
public String toClient(Object i)
{
return i.toString();
}
Creating Custom Components
[ 214 ]
public Object toValue(String s)
{
return new Integer(s);
}
}
To select a month, it will be convenient to have an appropriate enumeration and to
use the already familiar EnumSelectModel with it. Here is a possible implementation
for such an enumeration:
package com.packtpub.celebrities.util;
public enum Month
{
JANUARY (0),
FEBRUARY (1),
MARCH (2),
APRIL (3),
MAY (4),
JUNE (5),
JULY (6),
AUGUST (7),
SEPTEMBER (8),
OCTOBER (9),
NOVEMBER (10),
DECEMBER (11);
private Month(int order)
{
this.order = order;
}
private int order;
public int getOrder()
{
return order;
}
}
Each month in this enumeration is associated with an integer number that is equal to
the numeric value of the same month in the java.
Pages:
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269