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.
Compared to the Validation App discussed in Chapter 9, we now deal with the following new issues:
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 enum
classes;
single-valued enumeration
attributes, like Book::originalLanguage
, requiring the
JPA annotation @Enumerated
for defining the conversion between Java
enumeration literals and corresponding database table column values;
multi-valued enumeration
attributes, like Book::publicationForms
, requiring the
JPA annotation @Convert
with suitable arguments defining a JPA custom
converter for (de-)serializing collections of Java enumeration literals;
extending the methods Book.create
, and
Book.update
such that they take care of the
enumeration attributes.
In the user interface code we have to take care of
adding new table columns in
retrieveAndListAll.xhtml
;
adding suitable choice widgets in
create.xhtml
and
upate.xhtml
;
rendering multi-valued enumeration attributes in the
table view of retrieveAndListAll.xhtml
and in the choice widgets of create.xhtml
and upate.xhtml
(with the help of an
array of JSF SelectItem
s, each consisting of an
enumeration value and its label).