Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Checking null condition in sightly

Avatar

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
satishn21237075
Level 1

02-09-2018

<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

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

02-09-2018

Hi,

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

Please check Apache Sling :: Sling Models

Avatar

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
satishn21237075
Level 1

02-09-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

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

02-09-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>

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

02-09-2018

This to me is a sling-model issue/feature, can you share your code of this sling-model?

Avatar

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
satishn21237075
Level 1

03-09-2018

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. 

Avatar

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
satishn21237075
Level 1

03-09-2018

package org.dell.emc.aem.dellemcsupport.core.models;

import java.util.Date;

import javax.inject.Inject;

import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.annotations.Model;

import org.apache.sling.models.annotations.Optional;

@Model(adaptables=Resource.class)

public class DropDownModel {

  private String result;

  @Inject

  private String fullName;

  @Inject

  private String country;

  public String getDate() {

  return date;

  }

  @Inject

  private String date;

  public String getResult() {

  result=fullName+"satish";

  return result;

  }

  public String getCountry() {

  return country;

  }

  public String getFullName() {

  return fullName;

  }

}

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

03-09-2018

Hi,

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

@Inject @Optional

  private String fullName;

Avatar

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
satishn21237075
Level 1

03-09-2018

Is there no option with out giving @optional annotation.?

Avatar

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishn21237075
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
satishn21237075
Level 1

03-09-2018

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