Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

Sling Models + sightly to read multifield values

Avatar

Level 2

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:

content_structure.PNG

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

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 10

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 Mode...

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:

client.png

Lösung in ursprünglichem Beitrag anzeigen

5 Antworten

Avatar

Administrator

Avatar

Level 3

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

Avatar

Community Advisor

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();

Avatar

Korrekte Antwort von
Level 10

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 Mode...

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:

client.png

Avatar

Level 2

Thank you Scott.

Adding @Optional annotation worked for me.