Enumeration Implementation Issues
Let’s learn about some of the new issues that arise when implementing enumeration attributes in the application.
We'll cover the following
This chapter covers how to build a front-end web application with enumeration attributes using plain JavaScript. We’ll also learn how to deal with multi-valued attributes because enumeration attributes are multi-valued in many cases.
New Issues
In addition to the complications in the validation application that we discussed earlier, the following new issues arise when implementing enumeration attributes:
- We replace the ES5 constructor-based class definition of our model class
Book
with a corresponding ES2015class
definition. This provides a more convenient syntax while preserving the constructor-based semantics of JS classes. - Instead of defining explicit setters, we now use the ES5 feature of implicit
get
andset
methods for properties because they can be conveniently defined within a class definition. - Enumeration data types 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 addition to the complications above, the following problems arise in the code as well:
- In the model code, we now have to take care of:
- Define an ES2015 class for
Book
. - Define
get
/set
methods for all properties of theBook
class definition. - Define the enumerations with the help of a utility class
Enumeration
- Define the single-valued enumeration attributes
originalLanguage
, and categorize those attributes together with their check functions,checkOriginalLanguage
andcheckCategory
. - Define the multi-valued enumeration attributes
otherAvailableLanguages
andpublicationForms
together with their check functionscheckOtherAvailableLanguages
andcheckPublicationForms
. - Extend the methods
Book.update
andBook.prototype.toString
so that they take care of the added enumeration attributes.
- Define an ES2015 class for
- In the user interface, or view code, the following tasks must be performed:
- Add new table columns in
retrieveAndListAllBooks.html
along with suitable choice widgets increateBook.html
andupateBook.html
. - Create output for the new attributes in the
setupUserInterface()
method ofpl.v.retrieveAndListAllBooks
. - Allow input in the new attributes of the
setupUserInterface()
methods ofpl.v.createBook
andpl.v.updateBook
.
- Add new table columns in
Get hands-on with 1400+ tech skills courses.