Table of Contents
In this chapter, we show how to build a back-end web application with enumeration attributes, using Java with JPA and JSF. In addition to the topic of enumeration attributes, we also show how to deal with multi-valued attributes.
Enumeration datatypes have to be defined in a suitable way as part of the model code.
Enumeration attributes have to be defined in model classes and handled in the user interface with the help of suitable choice widgets.
In terms of coding, the new issues are:
In the model code we have to take care of
enumerations to be defined
in the form of Java
Book::originalLanguage, requiring the
@Enumerated for defining the conversion between Java
enumeration literals and corresponding database table column values;
Book::publicationForms, requiring the
@Convert with suitable arguments defining a JPA custom
converter for (de-)serializing collections of Java enumeration literals;
extending the methods
Book.update such that they take care of the
In the user interface code we have to take care of
adding new table columns in
adding suitable choice widgets in
rendering multi-valued enumeration attributes in the
table view of
and in the choice widgets of
upate.xhtml (with the help of an
array of JSF
SelectItems, each consisting of an
enumeration value and its label).