8. Quiz Questions

If you would like to look up the answers for the following quiz questions, you can check our discussion forum. If you don't find an answer in the forum, you may create a post asking for an answer to a particular question.

8.1. Question 1: JPA custom converter implementation class

Complete the following JPA custom converter class code, such that it serializes a value of type List<GenreEL> to String.:

@Converter
public class GenreConverter implements 
    AttributeConverter<_____________, ___________> {
  @Override
  public String convertToDatabaseColumn( 
      List<GenreEL> attributeValue) { ... }
}

8.2. Question 2: Cardinality constraints for enum attributes

Complete the definition of the languages property such that a minimum of three values are required.

@Entity
public class Book {
  @__________________
  private Set<LanguagesEL> languages;
}           

8.3. Question 3: JPA enum attribute serialization annotation

Which is the appropriate JPA annotation, including parameter(s), such that the value of the genre property is serialized and stored as enumeration literal name, i.e., as String, and not as ordinal values (indexes):

@Entity
public class Book {
  @Enumerated(_________________)
  @NotNull( message="A genre is required!")
  private GenreEL genre;
  ...
}

8.4. Question 4: JSF single-valued enum attribute

Which of the following is the name of a JSF element that can be used for rendering a choice widget for a single-valued enumeration attribute?

  1. O selectOneRadio

  2. O selectOnlyOne

  3. O radioGroup

  4. O radioSelect

8.5. Question 5: JSF multi-valued enum attribute

Complete the following facelet code, such that the resulting HTML code consists of a checkbox group allowing to select multiple languages, when creating a new Book instance::

<h:form id="createBookForm">
  ...
  <h:outputLabel for="languages" value="Select languages " />
    <h:____________________ id="languages" value="#{book.languages}">
      <f:____________________ value="#{book.languageItems}" />
    </h:____________________>
  <h:/outputLabel>
  ...
</h:form>>