Multifield component creation error in AEM 6.5 | Community
Skip to main content
Jacket97
April 21, 2022
Solved

Multifield component creation error in AEM 6.5

  • April 21, 2022
  • 2 replies
  • 2489 views

Hello everyone!
I am trying to no avail to create a component for my Multifield, I have followed some guides (https://aemhints.com/2020/10/24/coral-nested-multifield-aem65/ ,https://blogs.perficient.com/2018/08/24/using-sling-models-with-nested-composite-mulitifields-in-aem-6-3/ ) but unfortunately it seems not to take the multifield field.

This is my html:

 

<multi jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/multifield" composite="{Boolean}true" fieldLabel="String"> <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./multifield"> <items jcr:primaryType="nt:unstructured"> <column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container"> <items jcr:primaryType="nt:unstructured"> <text jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldLabel="Text" name="./text"/> </items> </column> </items> </field> </multi>

 

 

this is the component:

@Model(...) public class Multi { @586265 @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) private String text; public String getText() { return text; } @586265 @14766979 @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) public java.util.List<String> multifield = new ArrayList<>(); }

 

But when I go to debug I see that nothing passes and always returns the null. What am I doing wrong?

 

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 milind_bachani

@jacket97 hi,

 

thanks for conforming, I think you are not supposed to use getter annotation with Arraylist.

Instead replace it with :

@Inject @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) public java.util.List<String> multifield;

 

public List<String> getMultifield() {
if(multifield!=null){
return new ArrayList<String>(multifield);
}else{
return Collections.emptyList();
}
}

2 replies

milind_bachani
Adobe Employee
Adobe Employee
April 21, 2022

Hey @jacket97 ,

 

Had a quick look of your code, I see following issues on my glance :
annotation is @Inject & NOT @inject also @Getter & NOT @getter.

Can you please check if you are importing and using correct annotations :

javax.inject.Inject;
jdk.nashorn.internal.objects.annotations.Getter;


OR is it the case that while pasting the ode you used small case by mistake ?

You can use this video reference as well : https://www.youtube.com/watch?v=TJaAdbkyPJQ


Thanks.

Jacket97
Jacket97Author
April 21, 2022

Thanks for the answer, in the code they are written correctly, it is just a mistake when I copied it in the question box

milind_bachani
Adobe Employee
milind_bachaniAdobe EmployeeAccepted solution
Adobe Employee
April 21, 2022

@jacket97 hi,

 

thanks for conforming, I think you are not supposed to use getter annotation with Arraylist.

Instead replace it with :

@Inject @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) public java.util.List<String> multifield;

 

public List<String> getMultifield() {
if(multifield!=null){
return new ArrayList<String>(multifield);
}else{
return Collections.emptyList();
}
}
Sanjay_Bangar
Community Advisor
Community Advisor
April 22, 2022

Hi @jacket97 ,

you can use simple in slingmodel

@586265 

public Resource multifield;

 in sightly:

<sly data-sly-use.model="yourmodel">

<data-sly-list.list1=model.multifield.listchildren">

like that you can access item.

 

Kr,

Sanjay