Checking null condition in sightly | Community
Skip to main content
September 2, 2018

Checking null condition in sightly

  • September 2, 2018
  • 1 reply
  • 17536 views

<div data-sly-use.dailogvalue="org.dell.emc.aem.dellemcsupport.core.models.DropDownModel"/>

<div data-sly-test="${dailogvalue.fullName}"> ${dailogvalue.fullName}</div>

I am getting error :

Caused by: org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class org.dell.emc.aem.dellemcsupport.core.models.DropDownModel

Could not inject private java.lang.String org.dell.emc.aem.dellemcsupport.core.models.DropDownModel.fullName caused by No injector returned a non-null value!

  at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:534)

  at org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:306)

  at org.apache.sling.models.impl.ModelAdapterFactory.createModel(ModelAdapterFactory.java:200)

  at org.apache.sling.scripting.sightly.models.impl.SlingModelsUseProvider.provide(SlingModelsUseProvider.java:132)

  at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:84)

As i am not providing any value to fullName parameter but data-sly-test command is not handling the null value. Please suggest what i am doing wrong.

AEM 6.2

Thanks

Satish

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

arunpatidar
Community Advisor
Community Advisor
September 2, 2018

Hi,

you need to add @Optional in your case if property values are not mandatory

Please check Apache Sling :: Sling Models

Arun Patidar
September 3, 2018

By making @Optional to property means if its not required. If some property is giving null value then how to check in sightly.

I think this is alternative solution but not to correct to check the null value.

Please correct me if i am wrong

Thanks,

Satish

September 3, 2018

Hi,

The issue is with Model class, add @Optional with @Inject e.g.

@Inject @Optional

  private String fullName;


I find the solution without using @Optional annotation.

<sly data-sly-test.div="${properties.fullName && properties.country && properties.date }">

<pre data-sly-use.dv="org.dell.emc.aem.dellemcsupport.core.models.DropDownModel">

${dv.fullName}

${dv.date}

${dv.country}

</pre>

</sly>

<sly data-sly-test ="${!div}">

<pre>

enter value through dialog

</pre>

</sly>

Now when there no input from dialog then  "enter value through dialog" this will print in the page.

Thanks,

Satish