Sling Models + sightly to read multifield values | Community
Skip to main content
Level 2
February 21, 2018
Solved

Sling Models + sightly to read multifield values

  • February 21, 2018
  • 5 replies
  • 12533 views

Hello Everyone,

I have a multifield which stores data in node structure. I am using sling models to read it. When i drag and drop the component,I get following error

"org.apache.sling.scripting.sightly.SightlyException: Identifier com.test.core.models.WCMUsejsDemo cannot be correctly instantiated by the Use API".

After page refresh there is no error.

Multifield is stored as shown below:

Code of WCMUsejsDemo:

import javax.inject.Inject;

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

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

@Model(adaptables=Resource.class)

public class WCMUsejsDemo {

@Inject

public Resource userstory;

}

Thanks,

Megha Gowroji

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 smacdonald2008

Best way in AEM 6.3 to use Multifield is to use the Granite/Coral MF type and Sling Models- as discussed here:

Adobe Experience Manager Help | Creating a HTL Repeating Data Set 6.3 Component that uses Sling Models

Notice the use of Sling Models and HLT to read the MF in this example.

Then you can easily render out the MF values to the web page - such as:

5 replies

Level 3
February 21, 2018

You should try using the @ChildResource annotation instead of @Inject

Ravi_Pampana
Community Advisor
Community Advisor
February 21, 2018

Yes using @ChildResource you can get multifield value

@ChildResource(injectionStrategy = InjectionStrategy.OPTIONAL)

private Resource multinodes;

Once you get the childResource, iterate through all the child nodes

Iterator<Resource> iterator = multinodes.listChildren();

smacdonald2008
smacdonald2008Accepted solution
Level 10
February 21, 2018

Best way in AEM 6.3 to use Multifield is to use the Granite/Coral MF type and Sling Models- as discussed here:

Adobe Experience Manager Help | Creating a HTL Repeating Data Set 6.3 Component that uses Sling Models

Notice the use of Sling Models and HLT to read the MF in this example.

Then you can easily render out the MF values to the web page - such as:

Level 2
February 22, 2018

Thank you Scott.

Adding @Optional annotation worked for me.