When use data-sly-use.multifield="${resource.path}/field" getting sling error | Community
Skip to main content
Level 2
June 14, 2024
Solved

When use data-sly-use.multifield="${resource.path}/field" getting sling error

  • June 14, 2024
  • 3 replies
  • 1995 views

I am getting below error when add the component in the AEM new page. Kindly suggest the correction, if anyone have the idea for code changes. 

 

ERROR:

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: No use provider could resolve identifier /***********_header/field

Cannot serve request to /content/project/path/test.html in /apps//project/path/webhelp-header/webhelp-header.html

Exception:

org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.a

 

My code in html:

<div class="contentArea" id="${properties.id}">
<h1>${properties.title}</h1>
</br>
<sly data-sly-use.multifield="${resource.path}/field"/>
        <sly data-sly-list.item=${multifield.listChildren}>
<h2>${item.text}</h2>
<p>${item.termDef  @2941342='html'}</p>
</sly>
</sly>
</br>
<P align="right" style="margin-right:30px"><a href="#top" TITLE="Back to top"><B>^</B></A></P>
<p>&nbsp;</p>
 
</div>

 

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

Hi @mohanasundaram 

where is the your file named field and have you create a model class for it because what i can see you are using resource.path, in Sightly refers to the absolute path of the current resource within the AEM content repository

If your component is included on a page located at /content/mysite/en/products/myproduct, then resource.path would return /content/mysite/en/products/myproduct
what i would suggest that If the script file (field) is located within the same folder as your component, use a relative path:

data-sly-use.multifield="./field" // "./" refers to the current component's folder

If you're using a Sling Model for the multifield functionality, the attribute should reference the model class path:

data-sly-use.multifield="com.your.package.FieldModel" // Replace with your actual model class path

feel free to reply if you need further clarifications.

Hope this helps!


3 replies

abhishekanand_
Community Advisor
Community Advisor
June 14, 2024

Hi @mohanasundaram 

AEM cannot find the script associated with the data-sly-use.multifield, In your case, it's looking for a script with the identifier /_header/field also i noticed

The data-sly-list attribute should be enclosed in double quotes.
You have nested <sly> tags, which is not necessary in this case. You can simplify it by removing the inner <sly> tag.

Check below blog to see the use case of HTL Java Use-API
https://experienceleague.adobe.com/en/docs/experience-manager-htl/content/java-use-api 

Abhishek Anand
Level 2
June 14, 2024

Hi Abhishek,

 

Thanks for the quick response.

 

After mode the changes also based on you suggestion still getting same error. i thought  "<sly data-sly-use.multifield="${resource.path}/field">" multifield need to change i am not sure how to change that. This same used some components for existing our project but all component not working with this check.

corrected code:

<sly data-sly-use.multifield="${resource.path}/field">
<sly data-sly-list.item="${multifield.listChildren}">

<a class="grayButton" data-sly-element="${!item.enableLink? 'span':'a'}" href="${item.link @1917396='html'}" >${item.button} </a>
</sly>
</sly>

 

Thanks,

Mohan

abhishekanand_
Community Advisor
abhishekanand_Community AdvisorAccepted solution
Community Advisor
June 14, 2024

Hi @mohanasundaram 

where is the your file named field and have you create a model class for it because what i can see you are using resource.path, in Sightly refers to the absolute path of the current resource within the AEM content repository

If your component is included on a page located at /content/mysite/en/products/myproduct, then resource.path would return /content/mysite/en/products/myproduct
what i would suggest that If the script file (field) is located within the same folder as your component, use a relative path:

data-sly-use.multifield="./field" // "./" refers to the current component's folder

If you're using a Sling Model for the multifield functionality, the attribute should reference the model class path:

data-sly-use.multifield="com.your.package.FieldModel" // Replace with your actual model class path

feel free to reply if you need further clarifications.

Hope this helps!


Abhishek Anand
h_kataria
Community Advisor
Community Advisor
June 14, 2024

It seems you are just trying to iterate over some composite multifield set in your component. If I have to take a guess your content structure looks something like 

componentNode field item0 item1

So to get the multifield properties and iterate, you could possibly do something like 

<sly data-sly-list.childResource="${resource.children}"> <sly data-sly-test="${childResource.name =='field'}" data-sly-list="${childResource.children}"> <a class="grayButton" data-sly-element="${!item.enableLink? 'span':'a'}" href="${item.link @ extension='html'}" >${item.button} </a> </sly> </sly>

Ofcourse this is just sample, you can do it better in a sling model as Abhishek suggested.
Hope this helps

Mahedi_Sabuj
Community Advisor
Community Advisor
June 16, 2024

To retrieve values from multiple fields, we typically use Sling Model. You can refer to the article for step-by-step instructions.

https://ms-29.com/aem/sites/fetch-multifield-values-using-sling-model 

Mahedi Sabuj