AD0-E103 Exam QuestionsBrowse all questions from this exam

AD0-E103 Exam - Question 14


A developer creates a custom component. The component dialog includes the following two fields:

The component should display the first "˜X' characters of the text entered in the "˜text' input where "˜X' is the number entered in the "˜charLimit' input. If zero, or no value, is entered in the "˜charLimit' input then the text should be unaltered. The developer creates the following Sling Model to perform the trancation:

A Null Pointer Exception occurs if NO charLimit values is set in the component dialog.

What should the developer do to resolve this issue?

Show Answer
Correct Answer: B,D

To resolve the Null Pointer Exception, the developer should add the @Default annotation to the 'charLimit' variable in the Sling Model. This annotation ensures that even if no value is set for 'charLimit', a default value of 0 will be used, preventing the Null Pointer Exception.

Discussion

3 comments
Sign in to comment
cs1979Option: B
Jul 27, 2020

Answer is B

chunpinOption: B
Jan 9, 2021

Answer: B A. Replace the defaultValue=”0″ attribute of the ‘charLimit’ field in the dialog with min=”0″. (min property is for minimum value allowed) B. Add the @Default annotation to the ‘chatLimit’ variable in the Sling Model. (Correct Answer) C. Replace the defaultValue=”0″ attribute of the charLimit field in the dialog with defaultValue=”{Long}0″. (No such property called defaultValue) D. Change the defaultInjectionStrategy of the Truncation Sling Model to DefaultInjectionStrategy.REQUIRED. (@Optional annotations are only evaluated when using the defaultInjectionStrategy = DefaultInjectionStrategy.REQUIRED (which is the default), )

AEMSROption: C
Jun 30, 2020

Ans is C

kasyap1125
Oct 16, 2020

The default value is set using 'value' property, NOT 'defaultValue'. Here @Default will work