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... ) 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 {
@inject
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String text;
public String getText() {
return text;
}
@inject
@getter
@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?
Solved! Go to Solution.
Views
Replies
Total Likes
@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();
}
}
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.
Thanks for the answer, in the code they are written correctly, it is just a mistake when I copied it in the question box
@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();
}
}