5. Displaying Value Sets for Multi-Valued Enumeration Attributes

In the case of a multi-valued enumeration attribute like otherAvailableLanguages or publicationForms, the Retrieve/List All view must show a value in the form of a comma-separated list, like "English, German, Spanish", as shown in the following table:

ISBN Title Year Orig. lang. Other avail. lang. Category Publication forms
006251587X Weaving the Web 2000 English German, French textbook pdf, hardcover
0465026567 Gödel, Escher, Bach 1999 French other paperback, epub
0465030793 I Am A Strange Loop 2008 Spanish English, German textbook pdf, epub

For this purpose, we define a method that creates the desired serialization of a multi-valued attribute and use it in the code of the facelet file retrieveAndListAll.xhtml from WebContent/views/books/. For the publicationForms attribute, the method code is as follows:

public String getPublicationFormsValues() {
  String result = "";
  if (this.publicationForms != null) {
    int i=0, n = this.publicationForms.size();
    for (PublicationFormEL pf : this.publicationForms) {
      result += pf.name().toLowerCase();
      if (i < n-1) result += ", ";
      i++;
    }
  }
  return result;
}

Notice that in the case of the publicationForms attribute, the underlying enumeration PublicationFormEL does not have a label property. Instead, we use the enumeration literal name in lowercase as the label.