3 Replies Latest reply on Jun 3, 2008 8:58 AM by Ilya Shaikovsky

    <rich:scrollableDatatable> selection

    k dcosta Newbie

      hi

      I am using a rich scrollable Datatable in my application.This table is populated according from a database, according to the value selected from a combo box.

      ie when the page is loaded, the grid is empty.Then the user selected a value from the combo box and at the backend, it fetches the value from the database and bind to the list and rerenders the grid to show the fetched value.

      In my datatable i have binded the selection attribute. My datatable contains a rich column and in it a button is there.And when the button is selected the it calls a take selection method. and i want to show the selected row values in the text boxes.


      <rich:scrollableDataTable value="#{programManager.listType}" var="program"
       width="100%" height="260px" rowKeyVar="rkv" rows="10"
       id="pgmList" rowClasses="row1,row2"
       selectedClass="gridselectedRow"
       selection="#{programBean.selection}">
      
      
       <rich:column width="97" id="select" headerClass="listhead"
       sortable="false" >
      
       <f:facet name="header" >
      
       <h:outputText value="Select" />
      
       </f:facet>
      
       <a4j:region>
       <h:commandButton id="btnSelection"
       image="../Images/copy_button.GIF"
       action="#{programManager.takeSelection}">
       <a4j:support event="onclick" reRender="formPanel"></a4j:support>
       </h:commandButton>
       </a4j:region>
       </rich:column>
      
      
       <rich:column width="220" id="pgmid" headerClass="listhead"
       sortable="false" >
      
       <f:facet name="header">
      
       <h:outputText value="#{programManager.id}" id="h_proId" />
      
       </f:facet>
      
       <h:outputText value="#{program.programID}" id="proId"></h:outputText>
       </rich:column></rich:scrollableDatatable>





      public String takeSelection() {
      
       System.out.println("inside take selection");
      
       try {
       Iterator<Object> iterator = programBean.getSelection().getKeys();
      
       while (iterator.hasNext()) {
      
       SimpleRowKey key = (SimpleRowKey) iterator.next();
      
       programBean.setProgramOID(ListType.get(key.intValue()).getProgramOID());
       programBean.setProgramID(ListType.get(key.intValue()).getProgramID());
       programBean.setProgramName(ListType.get(key.intValue()).getProgramName());
       programBean.setNewName(ListType.get(key.intValue())
       .getNewName());
       programBean.setDescription(ListType.get(key.intValue())
       .getDescription());
       programBean.setType(ListType.get(key.intValue()).getType());
      
       }
      
      
       } catch (Exception e) {
      
       e.printStackTrace();
       }
      
      
       return null;
       }



      My problem is
      When i select the value from the combo, the grid id populated correctly. and when i select the button in the table, first time its not going to the takeSelection() method binded to it and the grid values get disappear.after that when the value selected from combo, the grid again get populated and when i click the button , the grid is getting selected, but it shows the values of previous selection. it continues like this.

      Why is it so????
      i dono whether i have conveyed my problem correctly.
      If someone have any idea, plz help me.


      rgds