|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Initialize datagrid sort orderI'm using NetUI in a Weblogic Portal 10.2 portlet and I'm trying to make
sure my datagrid has a default order. Hence the following begin action: @Jpf.Action( forwards={ @Jpf.Forward(name="index", action = "sortOpenCalls") } ) protected Forward begin() { Forward forward = new Forward("index"); //by default, order by descending date DataGridConfig config = DataGridConfigFactory.getInstance(); Sort sortDate = config.createSort(); sortDate.setDirection(SortDirection.DESCENDING); sortDate.setSortExpression("latestInformationIssueDate"); List<Sort> sorts = Arrays.asList(new Sort[]{ sortDate }); SortModel sortModel = config.createSortModel(sorts); DataGridState dataGridState = DataGridStateFactory.getInstance(getRequest()).getDataGridState("openCallsGrid"); dataGridState.setSortModel(sortModel); return forward; } Then the sortOpenCalls action loads the data and actually applies the sort: @Jpf.Action(forwards = { @Jpf.Forward(name = "success", path = "BrowseOpenCalls.jsp", actionOutputs = { @Jpf.ActionOutput(name = "openCalls", type = eu.europa.ec.digit.cap.portal.dto.CallListItem[].class, required = true), @Jpf.ActionOutput(name = "latestDatesOfCallPublications", type = java.util.Date[].class, required = true) }) }) public Forward sortOpenCalls() { Forward forward = new Forward("success"); DataGridState dataGridState = DataGridStateFactory.getInstance(getRequest()).getDataGridState("openCallsGrid"); List<Sort> sorts = dataGridState.getSortModel().getSorts(); List<Comparator> comparators = new ArrayList<Comparator>(); if(sorts != null){ for(final Sort sort:sorts){ comparators.add(new Comparator(){ public int compare(Object o1, Object o2) { try { if(sort.getDirection() == SortDirection.NONE){ return 0; } else if(sort.getDirection() == SortDirection.ASCENDING){ return BeanUtils.getSimpleProperty(o1, sort.getSortExpression()).compareTo(BeanUtils.getSimpleProperty(o2, sort.getSortExpression())); } else if(sort.getDirection() == SortDirection.DESCENDING){ return -BeanUtils.getSimpleProperty(o1, sort.getSortExpression()).compareTo(BeanUtils.getSimpleProperty(o2, sort.getSortExpression())); } else return 0; } catch (IllegalAccessException e) { return 0; } catch (InvocationTargetException e) { return 0; } catch (NoSuchMethodException e) { return 0; } } }); } } CallListItem[] openCalls = callService.getOpenCalls(); if(comparators.isEmpty()){ forward.addActionOutput("openCalls", openCalls); } else { List<CallListItem> sortedOpenCalls = new ArrayList(Arrays.asList(openCalls)); Collections.sort(sortedOpenCalls, ComparatorUtils.chainedComparator(comparators)); forward.addActionOutput("openCalls", sortedOpenCalls.toArray(new CallListItem[0])); } Date[] dates = callService.getLatestDatesOfCallPublications(); forward.addActionOutput("latestDatesOfCallPublications", dates); return forward; } Unfortunately, when the portlet loads, it is well sorted by latestInformationIssueDate BUT in ASCENDING order instead of DESCENDING order. Any idea what I did wrong? Sébastien Arbogast http://sebastien-arbogast.com http://mooplan.com |
| Free embeddable forum powered by Nabble | Forum Help |