Saturday, December 21, 2013

binding MultiSelectionModel to checkBoxColumn in CellTable, but why checkBoxs in column were not AUTO-selected CORRESPONDINGLY to SelectionModel?

Here is my problem. I have simple table with 3 columns (Id, no, text) Id and no combination creates a unique key for each row.

Id - no - text  12 - 1 - my text1  12 - 2 - my text2  13 - 1 - cool  13 - 2 - cool2  13 - 3 - cool3  

Now, i want to load these data into a CellTable with 4 columns (the 1st column is checkBoxColumn, the other 3 columns are ID/No/Text textcolum. I also want to put a SelectAllCheckBox on the Header of checkBoxColumn so that when user click on selectAllCheckBox then all the current visible checkBoxes got selected (of cause celltable could have many page but it will select only the visible ones).

Here is the code, i finished all the requirements except 1, that is "when i clicked the selectAllCheckBox, theselectionModel got selected but the correspondingly checkBoxes were not selected.

Here is the Code.

public static final ProvidesKey<String[]> KEY_PROVIDER = new ProvidesKey<String[]>() {        @Override        public Object getKey(String[] item) {          String[] itemArr={item[0],item[1]};          return item == null ? null : itemArr;          }  };  

Here is the main CrllTable code:

final MultiSelectionModel<String[]> selectionModel = new MultiSelectionModel<String[]>(KEY_PROVIDER);    final CellTable<String[]> cellTable = new CellTable<String[]>();    Column<String[], Boolean> checkColumn = new Column<String[], Boolean>(                  new CheckboxCell(true, false)) {          @Override          public Boolean getValue(String[] object) {                  // Get the value from the selection model.                   String[] objectArr={object[0],object[1]};                     return selectionModel.isSelected(objectArr);                 }   };     cellTable.setSelectionModel(selectionModel);   CheckboxHeader selectAllCheckBoxHeader = new CheckboxHeader();   selectAllCheckBoxHeader.addValueChangeHandler(new ValueChangeHandler(){                @Override              public void onValueChange(ValueChangeEvent event) {                  // TODO Auto-generated method stub                  System.out.println("test");                  for (String[] item : cellTable.getVisibleItems()) {                          if (!selectionModel.isSelected(item)) {                          System.out.println(Arrays.toString(item));                        selectionModel.setSelected(item, true);                        }                  }              }      });    cellTable.addColumn(checkColumn, selectAllCheckBoxHeader);  

When I clikced the selectAll, then non of visible checkBoxes got check, but when printout

Set<String[]> selSet=selectionModel.getSelectedSet();  for(String[] s : selSet){    System.out.println("Mine: "+Arrays.toString(s));  }  

it showed the currect selected items

Suppose pageSize is 3, then Output :

Mine: [12,1,my text1]  Mine: [12,2,my text2]  Mine: [13,1,cool]  

So how to make visible checkBoxes got selected automatically EXACTLY and CORESPONDINGLY /In TANDEM as the selectionModel got selected

Note: I also tried cellTable.setSelectionModel(selectionModel, DefaultSelectionEventManager.<String[]> createCheckboxManager()); but not working.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment