get stuck with SingleSelectionModel

69 views
Skip to first unread message

tong123123

unread,
Feb 22, 2012, 4:53:13 AM2/22/12
to Google Web Toolkit
I create a radioCell class as follow:
public class RadioCell extends CheckboxCell {

/**
* An html string representation of a checked input box.
*/
private static final SafeHtml INPUT_SELECTED =
SafeHtmlUtils.fromSafeConstant("<input type=\"radio\" name=\"selected
\" tabindex=\"-1\" checked/>");
private static final SafeHtml INPUT_UNCHECKED =
SafeHtmlUtils.fromSafeConstant("<input type=\"radio\" name=\"selected
\" tabindex=\"-1\"/>");
@Override
public void render(Context context, Boolean value,
SafeHtmlBuilder sb) {
// Get the view data.
Object key = context.getKey();
Boolean viewData = getViewData(key);


if (value != null && value) {
sb.append(INPUT_SELECTED);
} else{
sb.append(INPUT_UNCHECKED);
}
}

}

everything is ok, when I select a radiobutton, it will be selected.
now I want to add a button and when press this button, it will give me
the selected record, I plan to use
SingleSelectionModel.getSelectedRecord(), and the following is the
selectionmodel:
final SingleSelectionModel<Log> singleSelectionModel = new
SingleSelectionModel<Log>(keyProvider);
singleSelectionModel.addSelectionChangeHandler(new
SelectionChangeEvent.Handler(){
@Override
public void onSelectionChange(SelectionChangeEvent event) {
// TODO Auto-generated method stub

singleSelectionModel.setSelected(singleSelectionModel.getSelectedObject(),
true);
table.redraw();
}});

table.setSelectionModel(singleSelectionModel);

but now a very strange thing occur, when I select a radiobutton in a
row of the table, the radio button will not selected, I need press the
radio button once more to get it selected, before adding the
singleselectionmodel,
no this problem occur!!

tong123123

unread,
Feb 22, 2012, 5:26:25 AM2/22/12
to Google Web Toolkit
is there a way to locate the previous selected object in
onSelectionChange event so I can set its value to false?
I found that although I set the selected object to true, but the
previous selected object is also true, and seems there is no method in
onSelectionChange event to get the previous selected object, any
method?

Kolban

unread,
Feb 22, 2012, 9:56:38 PM2/22/12
to google-we...@googlegroups.com
I think you need to keep your own state/local variable that holds a reference to the previously selected object.  The value of this variable would be changed whenever a new selection change event arrives.

tong123123

unread,
Feb 23, 2012, 2:07:57 AM2/23/12
to Google Web Toolkit
much thanks for your reply, it helps me a lot and can really solve my
problem.
through the struggling of this problem, I faced many problem as
follow;
1) I found that after setting SingleSelectionModel, the column
FieldUpdater and the CheckboxCell onBrowserEvent will not run
anymore, why will this happen? because
SelectionModel.SelectionChangeEvent hides the FieldUpdater and the
CheckboxCell onBrowserEvent?
2) I extends the CheckboxCell to make RadioCell, but in the code of
CheckboxCell, I really don't know what is "dependsOnSelection",
"handlesSelection"?
(from the comment, dependsOnSelection true if the cell depends on the
selection state. handlesSelection true if the cell modifies the
selection state....what does it means exactly???)
3) in the CheckboxCell render method, it has a segment
if (viewDagta != null && viewData.equals(value)){
clearViewData(key);
viewData = null;
}

what is the function of this statement?
Reply all
Reply to author
Forward
0 new messages