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 SelectModel


This is where we are going to create the model itself. The easiest way to do this is to extend the AbstractSelectModel class that comes with Tapestry. In this case we shall need to implement just two methods, and one of them will always return null.

  • List<OptionModel> getOptions()—returns a list of options to display, using an implementation of OptionModel such as the one created above.

  • List<OptionGroupModel> getOptionGroups()—used to display grouped options. Most often, only the getOptions method is used, and so this one should return null. And reversely, if what we want to display is a list of grouped options, the first method should return null while this one will do the job.

Here is how the class that works with Celebrity objects might look (please add it to the com.packtpub.celebrities.util package):

package com.packtpub.celebrities.util;
import com.packtpub.celebrities.model.Celebrity;
import java.util.ArrayList;
import java.util.List;
import org.apache...