I want to get list of components present in currentpage by using a component and there is a flag like while checkbox is checked those components will be add as list , By using Backend it should be present on screen.
CurrentPage : component 1
component 2
component 3
component 4
Any references please
Solved! Go to Solution.
Views
Replies
Total Likes
@keshava219 For this you can get list by following the below steps:
1. Create the sling model for the list component and get the currentPage using the annotation
@ScriptVariable
Map<String, String> map = new HashMap<String, String>();
map.put("path", <page-path>/jcr:content);
map.put("1_property", "sling:resourceType");
map.put("1_property.operation", "exists");
map.put("2_property", "sling:resourceType");
map.put("2_property.operation", "unequals");
map.put("2_property.value", "<project-name>/components/container");
map.put("3_property", "componentChecked");
map.put("3_property.value", "true");
map.put("group.p.and", "true");
map.put("p.limit", "-1");
try {
Session session = resourceResolver.adaptTo(Session.class);
Query query = builder.createQuery(PredicateGroup.create(map), session);
if (query != null) {
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
.............
}
}
} catch (IOException | RepositoryException e) {
logger.error("Error while processing data {}",e.getMessage());
}
@keshava219 For this you can get list by following the below steps:
1. Create the sling model for the list component and get the currentPage using the annotation
@ScriptVariable
Map<String, String> map = new HashMap<String, String>();
map.put("path", <page-path>/jcr:content);
map.put("1_property", "sling:resourceType");
map.put("1_property.operation", "exists");
map.put("2_property", "sling:resourceType");
map.put("2_property.operation", "unequals");
map.put("2_property.value", "<project-name>/components/container");
map.put("3_property", "componentChecked");
map.put("3_property.value", "true");
map.put("group.p.and", "true");
map.put("p.limit", "-1");
try {
Session session = resourceResolver.adaptTo(Session.class);
Query query = builder.createQuery(PredicateGroup.create(map), session);
if (query != null) {
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
.............
}
}
} catch (IOException | RepositoryException e) {
logger.error("Error while processing data {}",e.getMessage());
}
@ShaileshBassi one thing
I'm not able to get same tree structure in page component, Im getting different ordering,
path=mypage/tiles-list-tests/jcr:content
1_property=sling:resourceType
1_property.operation=exists
2_property=addToLocal
2_property.value=true
orderby=path
group.p.and=true
p.limit=-1
Your query can be simplified. You mentioned having a flag in each component node, and if that flag is present, you want to fetch it. You can also check the possible value of the flag. Your query can be as straightforward as follows:
path=/content/<your-path>
1_property=<propertyName>
1_property.operation=exists
2_property=<propertyName>
2_property.value=<value>
orderby=@jcr:path
p.limit=-1
To order your query by path, use `@jcr:path` (ref: This response ). You don't need to specify `group.p.and=true` since, by default, all groups are AND-ed between them.
Hope this helps. You can use this query in your backend using Querybuilder APIs, as mentioned above, and it should give you the required results.
Thanks
Veena ✌
HI @VeenaVikraman , thanks for the reply tried with below snippet in query
still the same thing like
component 4
component 2
component 5
component 3
component 1
its giving me like the above order and Im expecting based on page structure.
component 1
component 2
component 3
component 4
component 5
might be it was reading with the sling:resourceType?
Map<String, String> map = new HashMap<String, String>();
map.put("path", currentPage.getPath() + "/jcr:content");
map.put("1_property", "sling:resourceType");
map.put("1_property.operation", "exists");
map.put("2_property", "addToLocal");
map.put("2_property.value", "true");
map.put("orderby", "@jcr:path");
map.put("p.limit", "-1");
Views
Likes
Replies