0

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).

1 Answers1

0

The widget in GWT for this is RadioButton, take a look to the showcase

To use it in data grids, you can take this RadioButtonCell example.

For more info about this issue, you can read this thread or this one.

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
  • Thank you for your help, but in a basic single choice test you have no radiobutton. I found a css solution to have a "checkbox style". [link](http://jsfiddle.net/mq8Zq/). I going to overide render to do radioButton with same class and onBrowserEvent to retrieve my value. – PAul Pasque Jul 15 '13 at 06:36
  • why dont you have radio button?, the link you sent is actually a radio-button (obviously with a changed style) – Manolo Carrasco Moñino Jul 16 '13 at 07:44