Hi, I was used to work with WCMUsePojo, now I am starting to work with Sling Models. I am reading some documentation and I have followed some examples,
that makes all sense to me but my object @ValueMapValue is getting null and I can't find the problem. Can some please help me to understand what am I missing?
I have a component with a dialog to configure it.
I am very gratfull in advance
my component name is featuredicons and it has this dialog:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="nt:unstructured"
jcr:title="Featured Icons" sling:resourceType="cq/gui/components/authoring/dialog">
<content jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<tabs jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/tabs"
maximized="{Boolean}true">
<items jcr:primaryType="nt:unstructured">
<tab1 jcr:primaryType="nt:unstructured" jcr:title="Button"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<button jcr:primaryType="nt:unstructured" jcr:title="Button"
sling:resourceType="granite/ui/components/foundation/include"
path="/apps/test/components/content/dialogFragments/button/cq:dialog/content/items/tabs/items/button" />
</items>
</tab1>
<tab3 jcr:primaryType="nt:unstructured" jcr:title="Icons"
sling:resourceType="granite/ui/components/coral/foundation/container"
margin="{Boolean}true">
<items jcr:primaryType="nt:unstructured">
<columns jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
margin="{Boolean}true">
<items jcr:primaryType="nt:unstructured">
<well jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container">
<layout jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/layouts/well" />
<items jcr:primaryType="nt:unstructured">
<icons jcr:primaryType="nt:unstructured" jcr:title="Icons"
sling:resourceType="granite/ui/components/foundation/include"
path="/apps/test/components/content/dialogFragments/icon/cq:dialog/content/items/tabs/items/tab/items/columns/items/well/items/icons">
</icons>
</items>
</well>
</items>
</columns>
</items>
</tab3>
<tab4 jcr:primaryType="nt:unstructured" jcr:title="Image"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<button jcr:primaryType="nt:unstructured" jcr:title="Image"
sling:resourceType="granite/ui/components/foundation/include"
path="/apps/core/wcm/components/image/v1/image/cq:dialog/content/items/image" />
</items>
</tab4>
</items>
</tabs>
</items>
</content>
</jcr:root>
my model:
@Model(adaptables = Resource.class)
public class IconModel {
private final Logger LOG = LoggerFactory.getLogger(getClass());
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String icontText;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String iconCode;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String iconCharacter;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String iconColor;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String iconBgColor;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String openNewtabIcon;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String urlLinkIcon;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String urlIconInt;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String urlIconProtocol;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String urlIconExt;
public Logger getLOG() {
return LOG;
}
public String getIcontText() {
return icontText;
}
public String getUrlIconInt() {
return urlIconInt;
}
public String getUrlIconProtocol() {
return urlIconProtocol;
}
public String getUrlIconExt() {
return urlIconExt;
}
public String getIconCode() {
return iconCode;
}
public String getIconCharacter() {
return iconCharacter;
}
public String getIconColor() {
return iconColor;
}
public String getIconBgColor() {
return iconBgColor;
}
public String getOpenNewtabIcon() {
return openNewtabIcon;
}
public String getUrlLinkIcon() {
return urlLinkIcon;
}
public void setIcontText(String icontText) {
this.icontText = icontText;
}
public void setIconCode(String iconCode) {
this.iconCode = iconCode;
}
public void setIconCharacter(String iconCharacter) {
this.iconCharacter = iconCharacter;
}
public void setIconColor(String iconColor) {
this.iconColor = iconColor;
}
public void setIconBgColor(String iconBgColor) {
this.iconBgColor = iconBgColor;
}
public void setOpenNewtabIcon(String openNewtabIcon) {
this.openNewtabIcon = openNewtabIcon;
}
public void setUrlLinkIcon(String urlLinkIcon) {
this.urlLinkIcon = urlLinkIcon;
}
My interface:
@ConsumerType
public interface FeaturedIcons {
/**
* Returns the list items, the Collection representing the list items.
*
* @return the list items
*/
Collection<IconModel> getListItems();
}
My implementation class:
@Model(adaptables = SlingHttpServletRequest.class, adapters = FeaturedIcons.class)
@Exporter(name = Constants.EXPORTER_NAME, extensions = Constants.EXPORTER_EXTENSION)
public class FeaturedIconsImpl extends ButtonModel implements FeaturedIcons {
private Collection<IconModel> listIcons;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private String[] listItems;
@PostConstruct
private void initModel() {
listIcons = IconsUtil.getListIcons(listItems);
}
@Override
public Collection<IconModel> getListItems() {
return listIcons;
}
}
Thanks once more!
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Please check Sling Models documentation Apache Sling :: Sling Models
and for implementation http://sgaem.blogspot.com/2017/08/deep-dive-on-sling-models-part-1.html
Views
Replies
Total Likes
Hi,
Please use the following code to get list injected in model:
@Model(adaptables = SlingHttpServletRequest.class, adapters = FeaturedIcons.class)
@Exporter(name = Constants.EXPORTER_NAME, extensions = Constants.EXPORTER_EXTENSION)
public class FeaturedIconsImpl extends ButtonModel implements FeaturedIcons {
private Collection<IconModel> listIcons;
@Inject
@Optional
private String[] listItems;
@PostConstruct
private void initModel() {
listIcons = IconsUtil.getListIcons(listItems);
}
@Override
public Collection<IconModel> getListItems() {
return listIcons;
}
}
Regards,
Himanshu
Views
Replies
Total Likes
Hi,
Please check Sling Models documentation Apache Sling :: Sling Models
and for implementation http://sgaem.blogspot.com/2017/08/deep-dive-on-sling-models-part-1.html
Views
Replies
Total Likes
Views
Likes
Replies