AD0-E103 Exam QuestionsBrowse all questions from this exam

AD0-E103 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.

Show Answer
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

5 comments
Sign in to comment
heenamadan
Jun 20, 2020

Ans should be D

rakayaD
Dec 16, 2020

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.

AkashD
Jun 27, 2020

Answer is D

Rajiv1908
Jul 16, 2020

I think answer should be C

mat2020
Aug 21, 2020

Answer D