I want to do a Single Choice Questions (or Single Choice Test) in GWT. So I need rows with only one checkbox selected per row.
How do I make a single selection? I thought about a SingleSelectionModel, but it can only be applied on a CellTable, not on a row.
I want a sort of "CheckBoxGroupCell", but I haven't found anything relevant on the web.
Thanks for your help!
Edit:
This is my solution for a MultipleChoice test:
Column<EvaluationDto, Boolean> getRadioButtonColumn(final int mark) {
return new Column<EvaluationDto, Boolean>(new CheckboxCell(true, false)) {
@Override
public Boolean getValue(EvaluationDto object) {
return object.getMark() == mark ? true : false;
}
@Override
public void render(Cell.Context context, EvaluationDto eval, SafeHtmlBuilder sb) {
RadioButton r = new RadioButton("");
// sur une ligne un seul radioButton sera selectionné
r.setName(eval.getQuestion().getCategory().getTitle() + eval.getQuestion().getTitle());
SafeHtml html = SafeHtmlUtils.fromTrustedString(r.toString());
sb.append(html);
}
@Override
public void onBrowserEvent(Context context, Element parent, EvaluationDto object, NativeEvent event) {
super.onBrowserEvent(context, parent, object, event);
object.setMark(mark);
}
};
}
And in css
input[type="radio"] {
-webkit-appearance: checkbox;
-moz-appearance: checkbox;
-ms-appearance: checkbox;
-o-appearance: checkbox; }
change all radiosButton to checkbox. (Don't work on ie)
After i just retrive all EvaluationDto (mark has been updated).