Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
755
change data's row after cell edition
posted

Hello,

I would like to make the following - I have web grid and each row contains data for one object. One column allows cell edition - select from all possible objects. When user selects the object then I would like to change the row according to new selected object.

Please, is it possible? I have been trying something but without result.

Here is some of my code:

JSF code: 

        <ig:gridView
            id="groupMemberShipTable"
            dataSource="#{assetController.asset.groups}"       
          style="width: 600px;">
          <ig:gridEditing enableOnMouseClick="single"
                  cellValueChangeListener="#{assetController.cellAssetGroupValueChangeListener}" /> 

                 ...

                    <f:facet name="editor">
                        <ig:dropDownList dataSource="#{assetController.allAssetGroups}"
                                smartRefreshIds="groupMemberShipTable" />
                    </f:facet>           

Java code: 

  public void cellAssetGroupValueChangeListener(CellValueChangeEvent event) { 
    DataModel dm = ((DataList)event.getComponent().getParent()).getDataSource();
    List<AssetGroup> origList = (List<AssetGroup>)dm.getWrappedData();
       
    AssetGroup ag = assetService.getAssetGroup(Long.valueOf((String)event.getNewValue()));
   
    origList.set(dm.getRowIndex(), ag);
   
    ((DataList)event.getComponent().getParent()).dataBind();
  } 
 

  public List<SelectItem> getAllAssetGroups() {
    if (allAssetGroups == null) {
      List<AssetGroup> groups = assetService.findAllAssetGroups();
     
      //convert to list of SelectItems
      allAssetGroups = new ArrayList<SelectItem>();
      for (AssetGroup g : groups) {
        allAssetGroups.add(new SelectItem(g.getId(), g.getName()));
      } //end-for
    }
    return allAssetGroups;
  }

 

Thank you in advance, PETER 

Parents
No Data
Reply
  • 1579
    Verified Answer
    posted

    Hello, PETER!

    This is the code of a sample application, that allows you to replace the object in a web grid's row using a dropDownList to select the new object. You can change the way tha data in the lists behave when making a new selection, but the way in that data in grid refreshes remains the same.

    Java code: 

    public class WebGridCriteriaBean {
     private List clientsIdList = null;  // List of SelectItems,
           // holds the ids of the objects

     private List clientsList = null;  // List of all possible objects

     private List selectedClientsList = new ArrayList(); // List of objects to be diplayed
            // in the Web Grid
     private GridView grid;


      ... // Initialization of lists


     public void onChangeSelection(ValueChangeEvent e) {
      System.out.println("NEW VALUE SELECTED: " + e.getNewValue());
     }


     public void onChangeCell(CellValueChangeEvent e) {

      /*
       * This code finds the object with the old Id in the list
       * and replaces it with the object correspoding to the
       * new Id, selected from the dropDownList
       */

      
      Clients client = (Clients) selectedClientsList.get(0);    // Class, that holds information like Id, Name, Address etc. of a client
      int index = 0;
      
      Iterator it = selectedClientsList.iterator();
      while(it.hasNext()){
       client = (Clients) it.next();
       if (client.getId().equalsIgnoreCase((String)e.getOldValue())){
        System.out.println(client.toString());
        index = selectedClientsList.indexOf(client);
        selectedClientsList.remove(client);
        break;
       } 
      }
      
        
      it = clientsList.iterator();
      while (it.hasNext()) {
       client = (Clients) it.next();
       if (client.getId().equalsIgnoreCase((String)e.getNewValue())) {
        System.out.println(client.toString());
        selectedClientsList.add(index, client);
        grid.dataBind();
        return;
       }
      }  
     }
    }

    JSF code:

    <ig:gridView id="clientTable" binding="#{wgCriteria.grid}" dataSource="#{wgCriteria.selectedClientsList}" pageSize="20">

    <ig:gridEditing enableOnMouseClick="single"

    cellValueChangeListener="#{wgCriteria.onChangeCell}"/>

    <f:facet name="header">

    <h:outputText value="Clients List"></h:outputText>

    </f:facet>

    <ig:column>

    <f:facet name="header">

    <h:outputText value="Client Id"></h:outputText>

    </f:facet>

    <f:facet name="editor">

    <ig:dropDownList smartRefreshIds="clientTable" dataSource="#{wgCriteria.clientsIdList}" valueChangeListener="#{wgCriteria.onChangeSelection}"/>

    </f:facet>

    <h:outputText value="#{DATA_ROW.id}"></h:outputText>

    </ig:column>

    ... <@-- Any other columns --@>

    </ig:gridView>

    Thanks!

    --Bozhidar

Children
No Data