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>
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Anilkumar9
What issue are you facing?
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.
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.
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:
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.
Thank you for your willingness to help; your support means a lot
@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.
Views
Replies
Total Likes
yes, @kautuk_sahni those suggestions are really helpful. Thanks!
Views
Likes
Replies
Views
Likes
Replies