Book Image

Tapestry 5: Building Web Applications

Book Image

Tapestry 5: Building Web Applications

Overview of this book

Table of Contents (17 chapters)
Tapestry 5
Credits
About the Author
About the Reviewers
Preface
Foreword
Where to Go Next

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...