Hi all,
Just preface this post, I'm very new to Java development... so I could be missing something basic.
Basically, I'm forking the list component in libs/foundation and want to have the pages be descending (reverse), versus the default ascending. I've tried various things in the dialog in CRXDE Lite but can't seem to get this to work. I did see the capability is listed under the Predicate class, but I have no idea how to make that work from the dialog side of things.
Could someone please help? Thank you!
Solved! Go to Solution.
Hi, i chose to implement a simple dialog choice as a dropdown with Ascending/Descending.
<sortingOrder jcr:primaryType="cq:Widget" defaultValue="asc" fieldLabel="Sort" name="./sorting-order" type="select" xtype="selection"> <options jcr:primaryType="cq:WidgetCollection"> <asc jcr:primaryType="nt:unstructured" text="Ascending" value="asc"/> <desc jcr:primaryType="nt:unstructured" text="Descending" value="desc"/> </options> </sortingOrder>
Then you can use this in a number of ways.
If you want to make use of the standard cq list there is a possibility to create you own comparator(or one for sorting asc and one for desc) to pass onto the list with the funtion setOrderComparator(Comparator<Page> obc). This comparator then has to sort the pages differently depending on the choice in the dropdown. There are loads of examples on the web how you implement of a comparator.
There is also an option to pass a querybuilder to the list itself in which you have to supply the parameters for a query to fetch the resources of your choice. In this you can then pass the chosen parameter for the sorting so that the query ultimately returns the list of results in the right order. A small code example below:
Map<String, String> map = new HashMap<String, String>(); //... add the rest of the options here map.put("orderby.sort", SORTING_ORDER_VALUE); //Here you put the value for sorting
This documentation will also help you with that:
http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5dam/query_builder.html
Good luck
/johan
Hi, i chose to implement a simple dialog choice as a dropdown with Ascending/Descending.
<sortingOrder jcr:primaryType="cq:Widget" defaultValue="asc" fieldLabel="Sort" name="./sorting-order" type="select" xtype="selection"> <options jcr:primaryType="cq:WidgetCollection"> <asc jcr:primaryType="nt:unstructured" text="Ascending" value="asc"/> <desc jcr:primaryType="nt:unstructured" text="Descending" value="desc"/> </options> </sortingOrder>
Then you can use this in a number of ways.
If you want to make use of the standard cq list there is a possibility to create you own comparator(or one for sorting asc and one for desc) to pass onto the list with the funtion setOrderComparator(Comparator<Page> obc). This comparator then has to sort the pages differently depending on the choice in the dropdown. There are loads of examples on the web how you implement of a comparator.
There is also an option to pass a querybuilder to the list itself in which you have to supply the parameters for a query to fetch the resources of your choice. In this you can then pass the chosen parameter for the sorting so that the query ultimately returns the list of results in the right order. A small code example below:
Map<String, String> map = new HashMap<String, String>(); //... add the rest of the options here map.put("orderby.sort", SORTING_ORDER_VALUE); //Here you put the value for sorting
This documentation will also help you with that:
http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5dam/query_builder.html
Good luck
/johan
Thank you! The comparator ended up being the most straightforward route.
For anyone else with a similar thing, this is what I ended up doing:
List list = new List(slingRequest, new PageFilter()); // Quick & dirty descending sort (dateField is in YYYY-MM-dd format) list.setOrderComparator(new Comparator<Page>() { public int compare(Page p1, Page p2) { String dateString1 = p1.getProperties().containsKey("publishDate") ? p1.getProperties().get("publishDate", String.class) : null; String dateString2 = p2.getProperties().containsKey("publishDate") ? p2.getProperties().get("publishDate", String.class) : null; return dateString2.compareTo(dateString1); } }); request.setAttribute("list", list);
Views
Replies
Total Likes
Views
Likes
Replies