Expand my Community achievements bar.

SOLVED

What would be reason for Sightly execption: cannot get default description.

Avatar

Level 3

I have created a multifield component with a sling model. I cannot render the content using sling models.

Error: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript:

=============== SocialShareItemsModel =====================

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

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

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

import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

 

@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

public class SocialShareItemsModel {

 

@ValueMapValue

private String socialicon;

 

@ValueMapValue

private String socialMediaUrl;

 

public String getSocialicon() {

return socialicon;

}

 

public String getSocialMediaUrl() {

return socialMediaUrl;

}

}

=============================SocialShareModel======================================

import java.util.ArrayList;

import java.util.List;

import org.apache.sling.api.SlingHttpServletRequest;

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

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

import org.apache.sling.models.annotations.injectorspecific.ChildResource;

 

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

public class SocialShareModel {

 

@ChildResource

private List<SocialShareItemsModel> mediaitems = new ArrayList<SocialShareItemsModel>();

 

public List<SocialShareItemsModel> getMediaitems() {

return mediaitems;

}

}

=================================== Sightly====================

 <sly data-sly-use.model="com.sample.core.models.SocialShareModel">
<sly-data-sly.list="${model.mediaitems}">
<a class="icon-link" href="${item.socialMediaUrl}">
<img src="${item.socialIcon}">
</a>
</sly>
</sly>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Anilkumar9 ,

 

Checkout this blog for detailed understanding on multi-field dialog. 

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

Hi @Anilkumar9 ,

 

Checkout this blog for detailed understanding on multi-field dialog. 

Avatar

Community Advisor

Hi @Anilkumar9 
What issue are you facing?



Arun Patidar

Avatar

Employee Advisor

Hi @Anilkumar9!

Would you mind sharing the error/exception including stack traces from the error.log file for this issues? This would help with further analysis and support.

Avatar

Community Advisor

Hi @Anilkumar9 

 

It looks like there might be a typo in your Sightly code where you're trying to access the socialicon property. The property in your Sling model is named socialicon, but in your Sightly code, you're trying to use item.socialIcon.

 

<sly data-sly-use.model="com.sample.core.models.SocialShareModel"> <sly data-sly-list="${model.mediaitems}"> <a class="icon-link" href="${item.socialMediaUrl}"> <img src="${item.socialicon}"> <!-- Corrected property name --> </a> </sly> </sly>

 

Here, I corrected the property name from socialIcon to socialicon to match your Sling model. Make sure to use the exact property names as defined in your model.

If the issue persists, you may also want to check if the mediaitems list is not null in your Sightly code to avoid potential null pointer exceptions:

<sly data-sly-use.model="com.sample.core.models.SocialShareModel"> <sly data-sly-list="${model.mediaitems}"> <sly data-sly-test="${item != null}"> <a class="icon-link" href="${item.socialMediaUrl}"> <img src="${item.socialicon}"> </a> </sly> </sly> </sly>
 

This checks if item is not null before trying to access its properties.

 

 

Also check your error.log file and share the complete error report so that we can debug it in better way. 

Avatar

Level 3

Thank you for your willingness to help; your support means a lot

Avatar

Administrator

@Anilkumar9 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni