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 Sling Model because of missing values properties, you need to make @Optional so that Model will returns null and sightly you can check with data-sly-test like <div data-sly-test="${dailogvalue.fullName}"> ${dailogvalue.fullName}</div>


Sorry, I have dialog and there is property full name . When i drag and drop component then this error comes.

But after providing value to property full name it get reflected to page.

While drag and drop time how to check null value condition in sightly.