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

Making DateInput a Field


To be a rightful member of the family of Form components that receive user input and can display validation errors, a custom component should implement the Field interface that contains four methods:

  • String getClientId()— should return a unique ID for the given component.

  • String getLabel()—naturally, should return a label.

  • String getElementName()— should return a name that will become the content of the component's name attribute.

  • boolean isDisabled()— should define whether the component is disabled (when it is typically greyed out and cannot accept user input).

Let's begin with the simplest. As DateInput doesn't have an element of its own, it doesn't have a dedicated name attribute so the getElementName method will be very simple:

public String getElementName()
{
return null;
}

The DateInput component does contain three Select components, but Tapestry will take care of the names of those.

The label can be specified by the component user, but not necessarily, so we...