3 Replies Latest reply on May 25, 2010 8:20 AM by ilya_shaikovsky

    How determine records in List using @Factory and extendedDataTable?

      Hello.

       

      I use @DataModel and @Factory seam-annotations to make data-list, and use it with extendedDataTable.

      In fact, my data model is a List<>.

       

      And everything is ok except one very difficult thing: I can't identify current record when is making selection in a table. The reason: selection has index of row, but I need id.

       

      I saw the example at demo: http://livedemo.exadel.com/richfaces-demo/richfaces/extendedDataTable.jsf?c=extendedDataTable&tab=usage

      But it't not my way. This example use ExtendedTableDataModel and DataProvider. And I don't want to use it instead of seam-annotations.

       

      My code is:

       

      <rich:extendedDataTable
                                  id="nummBillsTable"
                                  value="#{numBillList}"
                                  var="currentNumBill"
                                  selection="#{rpdAction.selectionNumBill}"
                                  selectionMode="single"
                                  tableState="#{rpdAction.numBillTableState}"
                                  enableContextMenu="false"
                                  rows="10"
                                  height="500px"
                                  width="1700px">
      
                              <a4j:support event="onselectionchange"
                                           action="#{rpdAction.takeCurrentNumBill}"
                                           reRender="changeValue, addValue, removeValue, changeNumBillPanel, addNumBillPanel">
                              </a4j:support>
      
                              <!--Some columns with sortBy-->  
      </rich:extendedDataTable>
      

       

       

       

      @Name("rpdAction")
      @Scope(ScopeType.PAGE)
      public class RpdAction {
      
      @DataModel
          private List<NumBill> numBillList;
          private SimpleSelection selectionNumBill = new SimpleSelection();
      
      @Factory("numBillList")
          public void initNumBillList() {
              if (numBillList == null)
                  getNumBillList();
          }
      
      public void takeCurrentNumBill() {
              Iterator<Object> iterator = getSelectionNumBill().getKeys();
              while (iterator.hasNext()) {            
                  int key = (Integer) iterator.next();
                  // key has index of current record in view.
                  // And if was sorting before, this index is wrong, I can't use the code:
                  currentNumBill = numBillList.get(key);
              }
          }
      
      public void setScrollerNumBillTable(int scrollerNumBillTable) {
              // in this method variable scrollerNumBillTable has index or row (not id)
              this.scrollerNumBillTable = scrollerNumBillTable;
          }
      
          public SimpleSelection getSelectionNumBill() {
              return selectionNumBill;
          }
      
      }