The good news, however, is that creating a custom service is very easy in Tapestry 5,
and we now have a good reason to create one and see how this is done.
Creating a Custom Service
A service is more or less like a standalone piece of functionality that can do
something useful for our application and is usually not page-specific. It can be
injected into any page where it might be needed. One example is a service that sends
email messages. Another example is the service we are going to create here??”it will
provide information on the locales supported by the application.
To create a custom service in Tapestry 5, first of all we need to formulate what
exactly that service is going to do??”and to create an appropriate service interface.
This is how it could look in our case:
package com.packtpub.celebrities.services;
public interface SupportedLocales
{
public String getSupportedLocales();
}
Next, we need to create an implementation of this interface, like this one:
package com.packtpub.celebrities.services;
import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.ioc.annotations.Symbol;
public class SupportedLocalesImpl implements SupportedLocales
{
private String supportedLocales;
public SupportedLocalesImpl(
@Inject
@Symbol("tapestry.
Pages:
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287