private int[] getSelectedRows(int[] selectedRowsNumber, Map[] selectedRowsKeys, Tab tab) {
    if (selectedRowsKeys == null || selectedRowsKeys.length == 0) return new int[0];
    // selectedRowsNumber is the most performant so we use it when possible
    else if (selectedRowsNumber.length == selectedRowsKeys.length) return selectedRowsNumber;
    else {
      // find the rows from the selectedKeys

      // This has a poor performance, but it covers the case when the selected
      // rows are not loaded for the tab, something that can occurs if the user
      // select rows and afterwards reorder the list.
      try {
        int[] s = new int[selectedRowsKeys.length];
        List selectedKeys = Arrays.asList(selectedRowsKeys);
        int end = tab.getTableModel().getTotalSize();
        int x = 0;
        for (int i = 0; i < end; i++) {
          Map key = (Map) tab.getTableModel().getObjectAt(i);
          if (selectedKeys.contains(key)) {
            s[x] = i;
            x++;
          }
        }
        return s;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("fails_selected"), ex);
        throw new XavaException("fails_selected");
      }
    }
  }
 private TableModel getTableModel(
     HttpServletRequest request,
     Tab tab,
     int[] selectedRows,
     boolean labelAsHeader,
     boolean format,
     Integer columnCountLimit)
     throws Exception {
   TableModel data = null;
   if (selectedRows != null && selectedRows.length > 0) {
     data = new SelectedRowsXTableModel(tab.getTableModel(), selectedRows);
   } else {
     data = tab.getAllDataTableModel();
   }
   return new TableModelDecorator(
       request,
       data,
       tab.getMetaProperties(),
       Locales.getCurrent(),
       labelAsHeader,
       format,
       columnCountLimit);
 }