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.
Complete the following code, with the correct Java Bean validation
annotation, so that the attribute title
has a minimum
length of 2 and a maximum length of 40:
@Entity @Table( name="books")
public class Book {
@________________________
private String title;
}
Which validation annotations are needed for requiring a (not-null) value for an attribute both in the Java EE model layer and in the database of an app?
☐ @NotNull( message = "A value is
required")
☐ @Column( nullable = false)
☐ @Size( min = 0)
☐ @Min( value = 0)
Complete the following code for defining a @LessThan100YearsOld
annotation that checks if a given Date
attribute value does not date back more than 100 years and the Java implementation class is LessThan100YearsOldImpl
:
@Target( ElementType.________________ ) @Constraint( validatedBy = ______________________________) public @interface LessThan100YearsOld { String message() default "The date must not be older than 100 years!"; } public class LessThan100YearsOldImpl implements ConstraintValidator<LessThan100YearsOld, _____________________> { @Override public void initialize( LessThan100YearsOld arg0) { ... } @Override public boolean isValid( Date date, ConstraintValidatorContext context) { ... } }
Complete the following JSF snippet such that the title
attribute value of
the entity book
is validated by the custom method
Book::checkTitle
:
<h:form id="createBookForm"> ... <h:outputLabel value="Title: "> <h:inputText id="title" value="#{book.title}" ______________="#{__________________________}" /> </h:outputLabel> ... </h:form>
Complete the following JSF snippet, such that any (possible) error messages resulting
from validating the title
attribute value of the book
entity are
displayed in the user interface:
<h:form id="createBookForm"> ... <h:outputLabel for="title" value="Title: "> <h:inputText id="title" value="#{book.title}" /> </h:outputLabel> <h:__________________ for="_______________" errorClass="error" /> ... </h:form>