Here we shall consider the simplest approach, and in Chapter 8
we'll experiment with a more powerful one.
First of all, we need to create an enumeration to work with the component. It will
be appropriate to name it Country and put into the com.packtpub.celebrities.
model package:
package com.packtpub.celebrities.model;
public enum Country
{
GERMANY, UK, USA
}
I have listed only a few countries here, but you can add as many as you wish. Next,
let's configure the page class to work with the new component:
@Inject
private Messages messages;
public SelectModel getCountries()
{
return new EnumSelectModel(Country.class, messages);
}
@Persist
private Country country;
public Country getCountry()
{
return country;
}
public void setCountry(Country country)
{
this.country = country;
}
Simple Components
[ 122 ]
Interestingly, we are creating an instance of EnumSelectModel, one of
implementations of the SelectModel interface that comes with Tapestry. The
constructor of EnumSelectModel takes two parameters??”the class of an enumeration
that should be used as the source of options and some mysterious Messages object
which we have injected into the page class. What is this Messages object?
Here we are coming very closely to the topic of internationalization and localization
that will be thoroughly discussed in Chapter 7.
Pages:
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166