5. Show multi-valued properties for the List Objects Use Case

In the case of multi-valued properties, (e.g., otherAvailableLanguages), the List All view must show a value in the form of value1, value2, ..., valueN, (e.g., English, German, Spanish), as shown in Figure 9.4 below.

Figure 9.4. The user interface for listing all the book records with the corresponding attribute values

The user interface for listing all the book records with the corresponding attribute values

For this case, we define a method which creates the desired multi-valued attribute string serialization, and we use it within the JSF WebContent/views/books/listAll.xhtml view file. For the case of of otherAvailableLanguages attribute, the following method is defined, but the same technique applies also for the publicationForms attribute:

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 for the case of PublicationFormEL enumeration we do not use a label property, instead we use the enumeration literal name in lowercase as the label. The method code creates the string which contains the serialization as is should be shown by the UI. In the view code, the method is used as shown below:

<ui:composition template="/WEB-INF/templates/page.xhtml">
  <ui:define name="content">
    <h:dataTable value="#{bookController.books}" var="b">
      ...
      <h:column>
        <f:facet name="header">Other available languages</f:facet>
        #{b.otherAvailableLanguagesValues}
      </h:column>
      ...
    </h:dataTable>
    <h:button value="Main menu" outcome="index" />
  </ui:define>
</ui:composition>

The JSF expression, #{b.otherAvailableLanguagesValues}, is used to invoke the getPublicationFormsValues method and it uses the returned string serialization to display the value in the view.