I am trying to figure out how to use GWT Editor when my model has a field that is a Set, List, etc.
I have this entity proxy:
public interface MyModel {
void setSomeCollection(Set<String> c);
Set<String> getSomeCollection();
}
Here is my multiselect field. I am extending ListBox so that I can change some of its behavior later.
public class DualListBox extends ListBox implements LeafValueEditor<Set<String>> {
public DualListBox() {
super(true);
}
@Override
public void setValue(Set<String> values) {
if (values == null) {
return;
}
for (String value : values) {
for (int i = 0; i < getItemCount(); i++) {
if (getValue(i).equals(value)) {
setItemSelected(i, true);
} else {
setItemSelected(i, false);
}
}
}
}
@Override
public Set<String> getValue() {
Set<String> values = new HashSet<String>();
for (int i = 0; i < getItemCount(); i++) {
if (isItemSelected(i)) {
values.add(getValue(i));
}
}
// Debug shows that the set of values is populated correctly..
return values;
}
}
Basically I just cant figure out how to get fields with a Set (I have tried List as well) to work with GWTs Editor framework. Debugging so far shows that the values are coming out of the editor correctly.
I have looked at ListEditor but that looks like its used to edit a list of more complex that object types; not a single field with multiple possible values. I am implementing the wrong editor type? Is GWT Editor not able to handle fields that are collections yet?
Ooops! The code I have will work correctly. I simplified my actual scenario a bit and I ended up finding my error. My real entity proxy looked more like:
ListBox always returns values as Strings! So the editor framework was probably having a hard time figuring out how to convert
Set<String>toSet<BrokerType>. Would have rather seen an error instead of silent failure, but oh well.This is the reason I was extending ListBox in the first place (to handle more complex types) so I guess I need to get that working before expecting the Editor framework to know what to do with the Set.