Hi! I want to store sort information (properties, orders (asc/desc)) for my IndexedContainer. What is the preffered way to do it?
At this moment I have the bad code which depends on current implementation of concrete container:
protected void storeSorters() {
if( container instanceof IndexedContainer ) {
IndexedContainer s = (IndexedContainer) container;
ItemSorter itemSorter = s.getItemSorter();
if( itemSorter instanceof DefaultItemSorter ) {
DefaultItemSorter defaultItemSorter = (DefaultItemSorter) itemSorter;
//private java.lang.Object[] sortPropertyIds;
try {
Field field = DefaultItemSorter.class.getDeclaredField("sortPropertyIds");
field.setAccessible(true);
try {
sortPropertyIds = (Object[])field.get(defaultItemSorter);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
} catch (NoSuchFieldException | SecurityException e) {
}
//private boolean[] sortDirections;
try {
Field field = DefaultItemSorter.class.getDeclaredField("sortDirections");
field.setAccessible(true);
try {
sortDirections = (boolean[])field.get(defaultItemSorter);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
} catch (NoSuchFieldException | SecurityException e) {
}
}
}
}
It would be perfect to get sort information legally. Any ideas?
Hi Anatoly,
It would be nice if DefaultItemSorter had getters as well as the setter, yeah. I suppose a workaround would be writing your own Sorter extends DefaultItemSorter that stores duplicates of the property id and direction arrays
Thank you, Johannes. As for me it would be good to have such getters in the Container.Sortable interface.