Tapestry has a special service
named PersistentLocale. To get access to this service we simply inject it into the
page. This is how it looks:
@Inject
private PersistentLocale persistentLocale;
And then we use the service's set method to set the new locale, like this:
persistentLocale.set(Locale.GERMAN);
Chapter 7
[ 183 ]
It's that simple! However, to make this functionality work, we need to run the
above line of code in some event handler. For simplicity, let's use the ActionLink
component at this stage.
We could use two links, one of them saying Switch to German, another Switch to
English, but, it will be slightly closer to a real life functionality if we use just one link,
Switch Locale, and it will do the job whatever the current locale is. Here is how such
a link could look in the page template:
Switch Locale
Before writing an event handler for this link, let's inject into the page yet another
resource??”the current application's locale:
@Inject
private Locale currentLocale;
And here is the event handler:
@OnEvent(component="switchlocale")
void changeLocale()
{
if (currentLocale.equals(Locale.
Pages:
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236