Exam AD0-E103 All QuestionsBrowse all questions from this exam
Question 91

A developer is working on the following Sling Model that is being used in a component.

The model must check if the configured value of the jcr:title property for the component matches the name of the current page. If the jcr:title property of the component has NOT been configured, then isMatchingTitle() must return false.

How should the developer inject the title property in this model?

A.

B.

C.

D.

    Correct Answer:

    The correct answer is D. The requirement is that the method isMatchingTitle() must return false if the jcr:title property of the component has not been configured. Using the @Required annotation would make the title injection mandatory, potentially leading to a NullPointerException if the property is not set. Instead, using the @Default annotation with an empty string ensures that the title has a default value when it is not provided, thus avoiding a NullPointerException and correctly returning false when the title is not configured. Therefore, the correct annotation is @ValueMapValue, @Named("jcr:title"), and @Default(values = "").

Discussion
heenamadan

Ans should be D

rakayaD

C cannot be as it is having required annotation. title must be optional with default empty string value. Then only it will return false. If it is C then NPE arises. Correct Ans is D.

mat2020

Answer D

Rajiv1908

I think answer should be C

AkashD

Answer is D