Sling model for adapting partial filtered list of grand-children.
Hello Community members,
This new look feels great btw. Congrats to Adobe.
My question is regarding sling model for a resource that I want to adapt. I understand that resource to be adapted is able to inject a list of grandchildren. But is there a way to exclude or filter out some values based on a condition. Like example below. How do I write a Sling model that returns only grandchild nodes that have prop1 value = male.
|-- myresource(to be adapted)
|-- children
|-- grandchild1 [prop1(name=gchildtype, value=male), prop2, prop3 and so on]
|-- grandchild2 [prop1(name=gchildtype, value=female), prop2, prop3 and so on]
|-- grandchild3 [prop1(name=gchildtype, value=male), prop2, prop3 and so on]
|-- grandchild4 [prop1(name=gchildtype, value=female), prop2, prop3 and so on]
@Model(adaptables = Resource.class)
public class MaleMembers {
@Inject
private List<GrandChildClass> children;
public List<GrandChildClass> getChildren() {
return children;
}
}
The above model will hold a list of all grandchildren. But how to get a partial list based on some condition like nodetype or any properties value, in this case gchildtype.
May be something like below could have been great:
@Inject @Filtered("gchildtype"="male")
private List<GrandChildClass> children;
Or May be in the GrandChildClass model, we could do something like:
@Model(adaptables = Resource.class)
public class MaleGrandChildClass {
@Inject @AdaptOnly("gchildtype"="male")
private String gchildtype;
public String getGchildtype() {
return gchildtype;
}
}