I have a celltable with 2 columns, name and cars he owns. One of the columns(cars) has to be a listbox. The person object will be rendered as a row in the celltable. The listbox will show the names of the cars owned by the person. Lets say,
Person jack has 3 cars(Merc, BMW, Honda) Person jill has 2 cars(Mini Cooper, Toyota Rav4)
I have seen the showcase and it implements a dropdown with fixed categories. But what i have is a dropdown whose contents will depend on contents of the Person object.
I also want to capture the event when user will select one of the cars in drop down. Any ideas how to do this?
AFAIK the CellWidgets
don't provide a cell type that supports dynamic lists out of the box.
However you can implement your own custom cell by deriving from AbstractCell
and implement the functionality yourself. See the GWT docs for more infos.
I would try to avoid making backend calls from inside the custom cell.
If possible try to add the list of available types in your DTO and then access that property from the render
method. Something along these lines:
public class DynamicSelectionCell extends AbstractCell<MyDTO> {
@Override
public void render(Context context, MyDTO value, SafeHtmlBuilder sb) {
if (value == null) {
return;
}
// render a selectionbox and dynamically add options by accessing the value.getAvailablOptions()
}
}
Add a getter to your MyDTO
object that returns the available types (Honda, etc) for the specific record and in the render method you just create a selectionbox.
You can check out the code for the SelectionCell how to properly render it.
Regarding the event handling you have to implement onBrowserEvent
. See here for more details.